GlideAjax and ScriptInclude how handle errors and different response status

Michele22
Tera Contributor

Hi there,

I'm new using GlideAjax and I have a question.

Using a proper script include I'0m able to call a function as Ajax request by a client script using a Glideajax call.

I see that the response is always '200 OK' I'd like to set in the script include different kind of response, for example '400 Bad Request' or '404 Not found' and so on.
I didn't find any kind of documentation that explain as handle and set the ajax response inside the script include.

I tried to throw an exception but I received on client script a 200 OK response with an empty 'answer'.

It is possible handle different kind and status of ajax responses? How it is possible?

 

thanks in advance

Michele

2 REPLIES 2

-O-
Kilo Patron
Kilo Patron

Edd the error code to the payload returned.

Plus you should not return error 400 anyway. If the request "reached" the Script Include, the conditions for throwing the error (the request could not be understood by the server due to malformed syntax) can no longer possibly be valid. If the server looked up your Script Include and called it, that is a pretty clear sign that the server did understand the request and no syntax was malformed. Throwing 404 is also not valid for pretty much the same reason: on one hand the URL for GlideAjax requests is always the same: xmlhttp.do on the other hand if processing the resource/URL went so far ahead as to use the Script Include to handle the content, that means the conditions for 404 Not Found (the server has not found anything matching the Request-URI.) are for sure not fulfilled - the requested URI has been found.

All in all one should not use protocol level errors in place of payload generation errors - my 2c.

dev115415
Tera Expert

Hello @Michele22  Did you get a way? I also need to know. Please help.