1
我試圖從使用正常的mootools請求切換到request.JSON,因爲我只使用json在客戶端和我的服務器之間進行通信。我有一個JSON請求定義爲:onFailure在響應狀態代碼是http 200中的mootools請求時調用.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});
我目前正在測試該鉻,並請求發佈的罰款,並與我期待的內容返回一個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並看到問題,那麼將不勝感激。