2014-02-26 38 views
1

我有搜索的google搜索,但沒有成功,努力實現解決方案IE 8+ XDomainRequest「POST」不是的WebAPI

我的代碼是

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; 

我的問題是請求打我的WebAPI,但數據爲空

回答

0

我已經用google搜索了很多天,最後我在同一個域的手段(Action in my application)上創建了AJAX請求。此操作調用Web API表示we can call server to server並將web api的響應發送到ajax

0

xdr.send($.parseJSON(params))似乎是錯的 - 你不應該將js對象傳遞給send方法 - 你應該傳遞json字符串或namevalue集合(如發佈表單時),指定正確的Content-type Hea der (application/json or application/x-www-form-urlencoded)

+0

它是'json字符串' – Amit

+0

但是$ .parseJSON(params)會將它反序​​列化到一個對象,如果參數是json字符串不解析它。 – lavrik

+0

請檢查我更新的問題 – Amit