Reputation: 11
I am trying to send a POST request to a Restful service with jquery, where the type of data sent is xml.
The Rest service works since I tested it from Chrome Rest plugin. I made it work for GET XML, GET JSON and POST JSON, but no way with POST XML.
Here goes the code. I do not get any error, but the invocation is not a success:
$.ajax({
type: "POST",
url: "http://[...]",
dataType: "xml",
contentType: "application/xml"
data: "<Category><categoryId>007</categoryId><categoryName>Ajax</categoryName></Category>",
success: function (res) {
alert("XML: it works!");
},
error: function (res) {
alert("XML: not working! " + res.statusText);
}
});
Upvotes: 1
Views: 8489
Reputation: 5598
I know this is quite old, but you need a comma before data
...
$.ajax({
type: "POST",
url: "http://[...]",
dataType: "xml",
contentType: "application/xml",
data: "<Category><categoryId>007</categoryId><categoryName>Ajax</categoryName></Category>",
success: function (res) {
alert("XML: it works!");
},
error: function (res) {
alert("XML: not working! " + res.statusText);
}
});
Upvotes: 5