user2886614
user2886614

Reputation: 11

Jquery POST XML to Rest service

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

Answers (1)

curly_brackets
curly_brackets

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

Related Questions