GlideAjax and ScriptInclude how handle errors and different response status

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2022 09:11 AM
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
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2022 01:01 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2023 03:26 AM
Hello @Michele22 Did you get a way? I also need to know. Please help.