我試圖通過使用jQuery(BaseCamp API)的ajax發出的請求,我似乎無法得到它的工作。我可以使用curl使它工作得很好,所以我知道這是我做錯了jQuery的事情。下面是其工作的curl命令:jQuery AJAX的帖子不工作,但與捲曲
curl -H "Accept: application/xml" -H "Content-Type: application/xml" -u my.user.name:my.password -d "<time-entry><person-id>123456</person-id><date>08/23/2009</date><hours>8</hours><description>This is a test.</description></time-entry>" https://my.url.updatelog.com/todo_items/1234567/time_entries.xml
,這裏是我的jQuery試圖代碼:
var post_url = bc_base_url + "/todo_items/" + todo_id + "/time_entries.xml";
var xmlData = "<time-entry><person-id>" + bc_user_id + "</person-id>" +
"<date>" + date + "</date>" +
"<hours>" + time + "</hours>" +
"<description>" + description + "</description>" +
"</time-entry>";
$.ajax({
type: "POST",
url: post_url,
data: xmlData,
dataType: "xml",
contentType: "application/xml",
username: "my.user.name",
password: "my.password",
processData: false,
success: function(msg) {
alert("successfully posted! msg: " + msg + ", responseText = " + this.responseText);
},
error: function (xmlHttpRequest, textStatus, errorThrown) {
alert("error : " + textStatus + ", errorThrown = " + errorThrown);
alert("this.reponseText = " + this.responseText);
}
})
人有什麼想法?
謝謝!
當您在Firebug中查看錯誤時會返回什麼錯誤?它可能是跨域問題嗎? – seanmonstar
您是否發佈到相同的域名? – karim79
僅供參考,已接受答案中的鏈接轉到Go-Daddy停放的域頁面。 –