簡體   English   中英

jQuery getJSON 請求返回空響應 - 相同域

[英]jQuery getJSON request returning empty response - same domain

我一直在尋找這個問題的解釋,但沒有得到任何地方......

我有一個 jQuery getJSON 請求:

$.getJSON("http://localhost:8080/context/json/removeEntity.html", {
    contentId : 1,
    entIndex : entityIndex
}, onRemoveEntityResponse);

由 URL 制成: http://localhost:8080/context/entity.html?contentId=2相同的域和端口)。

我通過 Firefox (5) 和 Chrome 中的螢火蟲看到的響應是空的。 同樣有趣的是,我在我的 Java 代碼中設置了一個斷點,該代碼服務於 JSON 請求並且它被命中,但只有在 Firefox 決定請求完成之后。

我還調試了一些 jQuery,這里是 AJAX 響應處理中涉及的一些變量(jQuery 1.5.2 未縮小):

[行:6651] deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] )

jqXHR: { readyState:0, responseText:"", status:0, statusText:"error", ...})
statusText: "error"
error: ""

有任何想法嗎? 提前致謝。

編輯:

Ignore the fact that the URL requests an HTML file, it's not really HTML, we use Tiles with Spring MVC to provide mappings to JSP files and Java controllers.

The JSON that should be returned by my Java controller is as follows (and is if I go to the URL directly):

{"oldEntityIndex":1,"isSuccess":true,"entityWasSaved":false}

我的愚蠢 - 我編寫的 jQuery 插件(並包含在此處的答案中)有一個錯誤。

The plugin had removed the onclick attribute of the element that sent the AJAX request off and bound it using jQuery bind , but what I had forgotten to do with the onclick handler was return the result. 因此,我的onclick處理程序返回false並阻止瀏覽器跟蹤底層鏈接被忽略,我猜瀏覽器隨后取消了 AJAX 請求,因為它知道它即將移動到新頁面。

浪費時間。 對不起。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM