-1

I wrote this following ajax request:

$.ajax({    
    type : "POST",
    processData:false,        
    crossDomain:true,
    crossOrigin:true,
    contentType:false,          
    headers: { 
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Methods": "POST",
        "Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept",   
    },
    url : 'my URI',
    data: formData,
    success : function(receivedData) {
        console.log("SUCCESS: ");
        alert(receivedData);
    }
});

But in the reply I'm getting this following message in by browser : Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at my URI. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

John
  • 1
  • 13
  • 98
  • 177
Alio
  • 9
  • 1
  • 1
  • 2
  • The first step should always be Googling the error message. This is a very common problem with thousands of solutions out on the Internet – Pekka Nov 30 '16 at 17:41

1 Answers1

-1

Try below code if it will not work then you need to implement server side cors enabling

$.ajax({    
        type : "POST",
        processData:false,

        crossDomain:true,
        crossOrigin:true,
        contentType:false,
        'Access-Control-Allow-Methods': 'POST',
        'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept',   
        },
        header:{'Access-Control-Allow-Origin': '*'},
        url : 'my URI',
        data: formData,
        success : function(receivedData) {
            console.log("SUCCESS: ");
            alert(receivedData);

            }

});

then you can use ajax call like that

$.ajax({
        url: 'http:ww.abc.com?callback=?',
        dataType: 'JSONP',
        jsonpCallback: 'callbackFnc',
        type: 'GET',
        async: false,
        crossDomain: true,
        success: function () { },
        failure: function () { },
        complete: function (data) {
            if (data.readyState == '4' && data.status == '200') {
                errorLog.push({ IP: Host, Status: 'SUCCESS' })
            }
            else {
                errorLog.push({ IP: Host, Status: 'FAIL' })
            }
        }
});
mohan rathour
  • 420
  • 2
  • 12
  • uhm... of the 9 ajax options you used here, only 5 of them actually do anything for jsonp requests. for the CORS option, crossDomain, headers, and crossOrigin are all irrelevant. – Kevin B Jan 18 '18 at 19:52