JQuery ajax JSONP POST changed to GET when cross domain

I have a WCF service waiting for POST. Using Fiddler, I found that in cross-domain situations, my POST request changed to GET, resulting in a 405 error from the 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?

thank

+5
source share
2 answers

No POST and JSONP. JSONP works by creating a new script tag in the DOM, which sends a GET request to the server. You give jQuery.ajax two incompatible parameters (POST, jsonp), and jQuery selects one of them.

: - CORS (Cross-Origin Resource Sharing), GET . WCF , WCF http://blogs.msdn.com/b/carlosfigueira/archive/2012/05/15/implementing-cors-support-in-wcf.aspx. p >

+10

GET, / JSON.stringify; . POST /.

0

All Articles