gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 22:09:58 25 4
gpt4 key购买 nike

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

最佳答案

JSON 格式错误。我有这个:

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

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

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

关于javascript - 在 mootools request.JSON 中响应状态代码为 http 200 时调用 onFailure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5759423/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com