开发者

jquery bug? jsonp in safari with objects doesn't work

I am getting a "parse error" with this function I'm working on. I was able to distill the problem into just barebones:

function test(){
dataobject={firstname:"John's"};
 $.ajax({
    url: "http://archive.cyark.org/fieldapp.php",
    dataType: "jsonp",
    data: {
        action:"getprojects1",
        dataobject:dataobject
    },
    success: function(data){
        alert("sucess!")
    },
    error: function(req, status, err){
      alert("An error occurred, are you sure you\'re connected to the internet?");
    }
});
}

To recreate the problem, you need to be in safari. It seems that the single quote in the object being sent开发者_JAVA技巧 is problematic. And it only is a problem in jsonp as well.

So two things, (1) what do I do to fix this problem? My objects might have a single quote in it and I have to account for that. And (2) is this a bug in jquery?


olle's answer for the same issue.
the specs say that in JSON you can only use double-quotes around keys and values so try it with double quotes. I am pretty sure your error will be solved.

you may want to use json.js to encode / escape special chars in the actual values so you don't run into problems with values containing " for instance. or the stringify method from http://www.json.org/js.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜