Reputation: 22691
I am looking to make HTTP POST Request with XML payload.
I have looked at this documentation: http://api.jquery.com/jquery.post/
Here the parameter data
is I believe I should be interested in.
However, it is not entirely very clear to me how do I specify the format of this data
parameter. In most of my earlier experience this parameter is application/x-www-form-urlencoded
However, my request has an XML payload.
Any pointers ?
Upvotes: 0
Views: 3980
Reputation: 27
You can post XML data as
$.ajax({
url: ajaxurl,
data: "<test><node1></node1></test>",
type: 'POST',
contentType: "text/xml",
dataType: "text",
success : parse,
error : function (xhr, ajaxOptions, thrownError){
console.log(xhr.status);
console.log(thrownError);
} });
Upvotes: 2
Reputation: 943585
$.post
is a shorthand function that covers some common usecases but has some unchangeable defaults. Use the $.ajax
method instead. It allows you to set the content type for the request.
contentType (default: 'application/x-www-form-urlencoded; charset=UTF-8')
Type: String
When sending data to the server, use this content type. Default is
"application/x-www-form-urlencoded; charset=UTF-8"
, which is fine for most cases. If you explicitly pass in a content-type to$.ajax()
, then it is always sent to the server (even if no data is sent). The W3C XMLHttpRequest specification dictates that the charset is always UTF-8; specifying another charset will not force the browser to change the encoding.
Upvotes: 2