Cross domain POST query using Cross-Origin Resource Sharing getting no data back

后端 未结 4 1320
独厮守ぢ
独厮守ぢ 2020-12-08 12:09

I\'m sending data cross domain via a POST request but the response isn\'t working, specifically, jQuery\'s success handler never gets called.

Stuff being used: Djang

4条回答
  •  臣服心动
    2020-12-08 12:40

    I don't think this is possible for security reasons. The only cross domain ajax calls which browsers allow, can be done using JSONP and these are exclusively GET requests.

    This will work:

    $.ajax({
        url: "http://somesite.com/someplace",
        type: "GET",
        cache: false,
        dataType: "JSONP",
        data: { ... },
        success: function( msg ) {
            alert(msg);
        },
    });
    

    This won't:

    $.ajax({
        url: "http://somesite.com/someplace",
        type: "POST",
        cache: false,
        dataType: "JSONP",
        data: { ... },
        success: function( msg ) {
            alert(msg);
        },
    });
    

提交回复
热议问题