1

In my web application, I need to send data to API hosted on a different domain, API works on the data received and then the jQuery AJAX work on the response of the API.

This call is working fine on Chrome and Firefox but not working for IE. AJAX is calling the API in IE10 but no data is sent with the call. I have added put_file_contents(fileName, receivedData) to check whether the API received any data or not. File is being created but it is blank. AJAX is not even calling API for IE<=9 (no file created and error part of ajax call is executed).

Code:

Have added this script before the AJAX Call to support CORS on IE - https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest/blob/master/jquery.xdomainrequest.min.js

jQuery(document).ready(function () {
    jQuery.support.cors = true;
    var link = new String(window.location) + "";
    jQuery.ajax({
        url: 'URL_OF_API',
        type: 'post',
        dataType: 'json',
        data: {
            'variable1' : 'value1',
            'variable2' : 'value2'
        },
        success: function (data) {
           //work on received data
        },
        error: function () {
           //This is executed in case of IE<=9
        }
    });
}); 


Please help. Thanks in advance!

linpar
  • 71
  • 1
  • 1
  • 7

1 Answers1

0

Debug with IE developer tool.

If You an error message like:

... Request method post was not present in the Access-Control-Allow-Methods list

Analyze Your response headers. You should see something like this:

Access-Control-Allow-Origin: http://www.yourdomain.com
Access-Control-Allow-Methods: POST

On which domain are You testing?

Maybe those links can help You more:

Community
  • 1
  • 1
czerasz
  • 13,682
  • 9
  • 53
  • 63