Skip to content

Error handling when accessing API through AJAX #241

@ki1022

Description

@ki1022

I am working on a project where I need to use html/javascript and I only want to interact with the API via ajax/json calls from a different server. I also don't want to heavily modify the default Userfrosting install and want to keep the bootstrap theme for administration on the server-side.

So if I access "load_current_user.php" from a browser, addAlert() and apiReturnError() will send client to login.php or their default page through a 302 re-direct. How can I maintain this functionality but optionally send back a json_encode() error to client when the request is made from AJAX call? How can the error handle function differentiate between the requests.

I thought of just calling a different php file, ex: load_current_user.php vs load_current_user_ajax.php, but that seems like to much extra work to do this for the whole API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions