1

我在谷歌上搜索但没有成功实现解决方案

我的代码是

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,但数据为空

4

2 回答 2

0

我已经用谷歌搜索并面临这个问题很多天,最后我AJAX在同一个域上创建了请求(Action in my application)。此操作是调用Web API手段we can call server to server并将响应从 web api 发送到ajax.

于 2014-03-04T11:52:20.653 回答
0

xdr.send($.parseJSON(params))似乎是错误的 - 你不应该将 js 对象传递给 send 方法 - 你应该传递 json 字符串或名称值集合(如发布表单时),指定正确的 Content-type Header(application/json or application/x-www-form-urlencoded)

于 2014-02-26T11:14:36.233 回答