I have a WCF Service that is expecting a POST. Using Fiddler I discovered that in cross-domain situations, my POST request was getting changed to a GET which results in error 405 from server.
$.ajax({
type: "POST",
url: "http://blah/blah.svc/Test",
data: JSON.stringify("{ 'WebUserID': 4 }"),
dataType: "jsonp", // from server
contentType: "application/json; charset=utf-8", // to server
success: function (data, status, xhr) {
alert("success--");
}
});
Can anyone shed some light on this?
Thanks
There's no POST and JSONP. JSONP works by creating a new script tag in the DOM which sends a GET request to the server. You're giving jQuery.ajax two incompatible parameters (POST, jsonp), and jQuery is choosing one over the other.
One update: you can use something like CORS (Cross-Origin Resource Sharing) to enable non-GET requests to cross-domain services. WCF doesn't support it out-of-the-box, but I wrote a post about implementing it in WCF at http://blogs.msdn.com/b/carlosfigueira/archive/2012/05/15/implementing-cors-support-in-wcf.aspx.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With