JQuery AJAX post not working but working with curl
I'm trying to make a post request via ajax using jQuery (for BaseCamp API) and I can't seem to get it to work. I can get it to work using curl just fine, so I know what I am doing wrong with jQuery. Here's the curl command running:
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
and here is the code I am trying to use with 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);
}
})
Does anyone have any idea?
Thank!
+2
source to share