Search code examples
jqueryasp.net-mvc-4asp.net-web-apixdomainrequest

IE 8+ XDomainRequest 'POST' not working with WebAPI


I have search on googled but no success to achieve the solution

My Code is

var xdr = new XDomainRequest();
if (xdr) {
    $.support.cors = true;
    xdr.open(method, svcUrl, true);
    xdr.onload = function () {
        var result = $.parseJSON(xdr.responseText);
        if (result === null || typeof (result) === 'undefined') {
            result = $.parseJSON(
                data.textContent);
        } 
        if ($.isFunction(successCallBackFunction)) {
            successCallBackFunction(result);
        }
    };
    xdr.onerror = function () {
        if ($.isFunction(errorCallBackFunction)) {
            errorCallBackFunction();
        }
    };
    xdr.onprogress = function () {};
    xdr.send(JSON.stringify(params));
}
return xdr;

My Problem is request is hitting my webapi but data is null


Solution

  • I have googled and faced this problem many days, at last I created AJAX request on same domain means (Action in my application). This action is calling Web API means we can call server to server and send the response from web api to ajax.