我正在尝试使用jQuery(用于BaseCamp API)通过ajax发布帖子请求,我似乎无法让它工作。我可以使用curl来使用它很好,所以我知道这是我用jQuery做错了。这是有效的curl命令:
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);
}
})
有人有什么想法吗?
谢谢!
答案 0 :(得分:4)
正如karim79所说,你不能发布到不同的域名。
有关更多选项,请参阅Nathan's post。
答案 1 :(得分:2)
将其发布到您的服务器,将帖子从应用程序代码传递到basecamp,然后将消息传回。