我正在尝试从正常的mootools请求切换到request.JSON,因为我只使用json在客户端和我的服务器之间进行通信。我有一个json请求定义为:
var jsonRequest = new Request.JSON({
url: '/ServletContext/servlet',
onRequest: function(){
// Just a class to make the cursor change to progress
container.addClass('request-waiting');
},
// validationMessages should be a json object containing
// messages on problems validating user input from server
onSuccess: function(validationMessages){
container.removeClass('request-waiting');
},
onFailure: function(requestObj){
container.removeClass('request-waiting');
}
}).post({'context': context,'title': title});
我目前正在使用chrome进行测试,请求发布正常,并返回带有我期望内容的http 200;但onFailure回拨不断被召唤。我想知道为什么没有调用onSuccess方法。
我在回复中(故意)发回的json字符串是:
"{titleErrors: [], contextErrors: ['Context must be more than 40 characters']}"
我正在使用mootools 1.3和tomcat 7。
编辑:在向上移动mootools堆栈后,我发现了对json.decode的调用,这是失败的。我猜这是因为我的json字符串格式错误。我没有长时间使用json,所以这不会让我感到惊讶,但我会认为这会起作用。我正在研究这个问题,但如果你能够看到我的json并看到问题,那将是值得赞赏的。
答案 0 :(得分:3)
json畸形。我有这个:
{titleErrors: [], contextErrors: ["Context must be more than 40 characters"]}
它应该是这个(注意变量名称引用):
{"titleErrors": [], "contextErrors": ["Context must be more than 40 characters"]}