javascript - Determine the data type of the HTTP request -


i see $.ajax() can use datatype property tell jquery kind of response expect server, json.

but on server side, how know data type requested?

i understand server should know send based on content of request, use case bit different here. have error handler built in php , i'd know in format output debug info. in case of fatal/syntax errors, warnings, script may not reach request handler function associated request.

there's content_type header apparently it's application/x-www-form-urlencoded, , it's sent on post requests.

and there's http_accept header looks application/json, text/javascript, */*; q=0.01. need parse string?

there no standard way client tell server data type wanted. clients not tell "i want text/plain" or "only html please" (this can assumed uri). tell can potentially interpret (http_accept) , post (content_type).

for server side error handler reliably determine output format use, pass additional request headers or query parameters request, example:

$.ajax({     ...     headers: {         "x-expected-format": "text/plain"     }     ... }); 

Comments

Popular posts from this blog

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -