I need to create a web server client in JavaScript and I have some problems to define Request headers.
I need POST method and Content-Type: "application/json".
I tried this:
$.ajax({
url: 'http://MyWebServiceAddress',
data: JSON.stringify({user:'user',pass:'pass'}),
type: 'POST',
crossDomain: true,
dataType: 'json',
success: function () {
alert("success")
},
error: function (xhr, ajaxOptions, thrownError) {
alert("Error: " + xhr.status + "\n" +
"Message: " + xhr.statusText + "\n" +
"Response: " + xhr.responseText + "\n" + thrownError);
}
});
But if I put contentType like this:
contentType: 'application/json; charset=utf-8',
and look then the request with Chrome Dev Tools I can see that method was changed to "OPTIONS" and type to "text/plain"
Anyone can help me? I don't have to use Ajax, so if someone know a good JavaScript library to make client easier, maybe can result my problems