JQuery.ajax () v1.5 returns "parsererror" for json data

I have this function to get the server id from the list. The function always returns "parsererror". I looked at the JSON data, but I can't get it to work, since jQuery rewrote ajax in version 1.5.

function server_id() { $.ajax({ type: "GET", url: "http://localhost/server_list.php", dataType: "json", success: function(data, status) { alert(status + "\n\n" + data.server_id); }, complete: function(data, status){ alert(status); } }); } 

server_list.php

  header('Content-type: application/json'); $output['server_id'] = '123'; print json_encode($output); 

In firebug Net → XHR reads it as JSON when it opens a tab, and the Response tab shows that below.

 {"server_id":"123"} 

I also tried setting the content type header as below, but no luck.

 Content-type: application/json 

UPDATED

I get "parsererror" if the validation plugin is downloaded from http://bassistance.de/jquery-plugins/jquery-plugin-validation docs.jquery.com/Plugins/Validation v1.7.

If you add a jquery flash drive, it will automatically add the jsonp callback to the query string, even if you set it to false or do not enable parms for jsonp. Very strange

Any ideas on how to fix it?

thanks

+7
source share
3 answers

It seems you need regular json communication ( dataType is "json" instead of "jsonp" and server_list.php sends json), but you are setting jsonp parameters. Remove the jsonp and jsonpcallback . Setting jsonp to false does not mean you disable it!

When these two lines are commented out, everything seems to work fine .

0
source

A simple solution here seems like jQuery 1.5 is not compatible with the 1.7 validation plugin. Switching to jQuery 1.4.x (or, otherwise, fixing or removing the code of the validation plugin as the proposed file flag) solves the problem.

Many thanks to those in this thread who identified the conflict. This saved me a bunch of headaches to debug jQuery code.

+2
source

I suffered a few days before finding this topic, thanks to those who pointed to jQuery.validate as the culprit.

In my testing, it actually seems jquery.validate-vsdoc.js, which is causing the problem, not the plugin itself if anyone likes it.

0
source

All Articles