How to Return Status Codes from Ajax Callbacks

Description

You can manually set the status code in an Ajax response.

Discussion

Setting the status code is a good technique to use if you need to test how your application will behave when the server returns status codes indicating a problem as occured, such as a 401 or 403 status. You can manually set the status code in an Ajax response by setting the Context.Response.StatusCode property in the Xbasic function that handles the Ajax callback.

Suppose you have a UX Component that has enabled client-side security events. When client-side security events are enabled in a UX Component, the securityNotAuthenticated and securityPermissionsDenied client-side events are available to you to add your own messages or error handling when the server returns a 401 or 403 status code. To test code you have added in these client-side events, you need to be able to emulate or trigger a 401 and 403 status code response from the Alpha Anywhere Application Server.

You can manually set the status code for the Ajax response in the Xbasic function that handles the Ajax callback. This could be done as follows:

function myXBFunction as c (e as p)

    Context.Response.StatusCode = 401

end function

See Also