【问题标题】:onFailure being called when response status code is http 200 in mootools request.JSON当 mootools request.JSON 中的响应状态代码为 http 200 时调用 onFailure
【发布时间】:2011-04-23 04:17:30
【问题描述】:

我正在尝试从使用普通的 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 并看到问题所在,那将不胜感激。

【问题讨论】:

    标签: javascript json tomcat mootools xmlhttprequest


    【解决方案1】:

    json 格式错误。我有这个:

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

    它应该是这样的(注意变量名的引号):

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

    【讨论】:

      猜你喜欢
      • 2013-10-20
      • 2021-10-21
      • 2020-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多