以下是包含對負責發出AJAX調用的JavaScript函數的調用的HTML。據我所知,錨標籤不應該有一個值屬性,但我用它與jQuery的.attr(「值」)方法。使用jQuery的AJAX - 語法錯誤?
<a href="javascript:;" onclick="ajaxTest();" title="Execute AJAX" value="executeAJAX">Execute AJAX</a>
以下是JavaScript函數。如果它有任何意義,它本身就包含在一個.js文件中。
function ajaxTest() {
$.ajax({
type: "POST",
url: "doAJAX",
data: {"selectedScope": "5",
"selectedView": "6"},
dataType: "text",
success: function(responseData) {
$("#replaceThis").append(responseData);
}
});
}
每次鏈接被點擊,出現在Firefox的Web控制檯一個「語法錯誤」消息。然而JavaScript似乎按預期工作。
我只是想了解爲什麼我得到的錯誤。
我應該補充說我正在使用jQuery 1.7.1。
我執行搜索和唯一的解決辦法我發現是,對「數據」選項鍵都應該包含在雙引號所以,我實現了,但我仍然得到語法。
謝謝。
EDIT:
Looking at the Firebug console, the code above doesn't trigger an error like it did in Firefox's console, however, I saw the following in the XML part of the POST Request:
XML Parsing Error: syntax error Location: moz-nullprincipal:{1d13df07-25fb-4058-9f82-ce1bef3c8949} Line Number 1, Column 1:
alskdfjlaksjdfjasdfl
^The "alskdfjlaksjdfjasdfl" is simply what I've set up my servlet to return as I test this stuff out.
This is somewhat weird because it seems like jQuery is trying to parse the response as XML although I've explicitly stated it to be text.
它看起來不像是關閉數據對象。數據:{「selectedScope」:「5」,「selectedView」:「6」,< - 在最後一個逗號前需要有一個} – Jemaclus
同樣的問題,firefox ajax試圖解析文本數據。 – fantastory