I’m using jQuery.get() to perform an AJAX call to a service.
My service returns a JSON object in this form
{
"ip" : "127.0.0.1",
"name" : "localhost"
}
That’s it (no html tags)
if I use jQuery.get() without specifying that my output is “json” (so leaving the 4th parameter empty) the output of the service is not automatically recognized as JSON.
Did I make any mistake in formatting the service output?
The format of the output is correct.
The result is most likely not returned with the content type
application/jsonbut for exampletext/html, which would lead jQuery to think that it’s not JSON.If the content type doesn’t match the data, you should specify the data type.
Related: how does jquery guess the better datatype in Ajax method?