我试图通过使用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停放的域页面。 –