简体   繁体   English

在mootools request.JSON中响应状态代码为http 200时调用onFailure

[英]onFailure being called when response status code is http 200 in mootools request.JSON

I'm trying to switch from using the normal mootools request to request.JSON since I'm using exclusively json to communicate between the client and my server. 我正在尝试从使用普通的mootools请求切换为request.JSON,因为我仅使用json在客户端和服务器之间进行通信。 I have a json request defined as: 我有一个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});

I'm currently testing this in chrome, and the request is posting fine, and returning an http 200 with the contents I'm expecting; 我目前正在chrome中进行测试,请求正常发布,并返回包含我期望的内容的http 200; but the onFailure call back keeps getting called. 但是onFailure回调会不断被调用。 I'm wondering why the onSuccess method is not being called. 我想知道为什么没有调用onSuccess方法。

The json string I'm sending back (intentionally) in the response is: 我在响应中有意发送回的json字符串是:

"{titleErrors: [], contextErrors: ['Context must be more than 40 characters']}"

I'm using mootools 1.3, and tomcat 7. 我正在使用mootools 1.3和tomcat 7。

EDIT: After going up the mootools stack a bit, I found a call to json.decode and this is failing. 编辑:向上上升了mootools堆栈后,我发现了对json.decode的调用,但失败了。 I'm guessing that is because my json string is malformed. 我猜这是因为我的json字符串格式错误。 I haven't been using json that long, so that wouldn't surprise me but I would have thought that this would work. 我没有使用json这么长时间,所以这不会令我感到惊讶,但我会以为这会起作用。 I'm looking into this but if you're able to eyeball my json and see the problem then that would be appreciated. 我正在调查此问题,但是如果您能够关注我的json并看到问题,那么将不胜感激。

The json was malformed. json格式错误。 I had this: 我有这个:

{titleErrors: [], contextErrors: ["Context must be more than 40 characters"]}

and it should have been this (note quotes around variable names): 并且应该是这个(注意变量名的引号):

{"titleErrors": [], "contextErrors": ["Context must be more than 40 characters"]}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM