服务器无法解析有效的json

Juz*_*Ali 10 ajax jquery json

我正在向URL发送此ajax请求,但服务器正在发送响应Unrecognized token 'naejzraieale': was expecting 'null', 'true', 'false' or NaN at [Source: org.eclipse.jetty.server.HttpInput@13367e3; line: 1, column: 25].

我的Ajax请求看起来像这样

$.ajax({url: "https://jsonparser.mydomain.com",
        contentType: 'application/json',
        type: "POST",
        data :{name : "juzer ali",
               email : "email@gmail.com",
               how : "Used jQuery.ajax from google chromes developer console",
               urls : ["https://chrome.google.com/webstore/search/",                                  "https://chrome.google.com/webstore/detail/", 
"https://github.com", "https://docs.google.com/document/d/edit?pli=1", "pro.appspot.com"]}
});
Run Code Online (Sandbox Code Playgroud)

编辑:请注意Unrecognized token 'naejzraieale':.在jr此错误字符串是从我传递数据对象的name属性.当我把这些字母大写时,我明白了(Unrecognized token 'naeJZRAIeale': was expecting 'null', 'true',)

Sak*_*tel 20

在将数据发送到服务器之前,您需要以JSON格式对其进行编码JSON.stringify和JSON.parse由最新的浏览器提供,但如果任何浏览器不支持,那么您可以使用jquery插件来执行相同的http://代码.google.com/p/jquery-json /,如果你使用这个插件,那么语法会有所不同

$.ajax({
       url: "https://jsonparser.mydomain.com",
       type: 'POST',
       contentType:'application/json',
       data: JSON.stringify({name : "juzer ali",
               email : "email@gmail.com",
               how : "Used jQuery.ajax from google chromes developer console",
               urls : ["https://chrome.google.com/webstore/search/",                                  "https://chrome.google.com/webstore/detail/", 
"https://github.com/", "https://docs.google.com/document/d/edit?pli=1", "pro.appspot.com"]}),
       dataType:'json'
});
Run Code Online (Sandbox Code Playgroud)

  • 3岁,但仍然和今天一样有用。但是很遗憾,在定义内容类型之后必须手动执行此操作 (2认同)