0

我创建了一个项目,它是一个 asp.net 项目,它有一个 Service1.asmx,我把这个项目托管到远程服务器上,就像一个子域 ( myservice.test.com/Service1.asmx ),我从一个带有 jquery ajax 方法的 asp.net 应用程序。此应用程序位于同一远程服务器上,当我调用 admin.test.com/Default.aspx(此页面使用 Web 服务 abow)时,我像子域( admin.test.com )一样托管它用 chrome 控制台查看,它说:* (Access-Control-Allow-Origin 不允许。) *4444

GET_CAT_ALL: function (userId, callback, callback_err) {
    try {
        $.ajax({
            type: "POST",
            url: myservice.test.com/Service1.asmx + "/GET_CAT_ALL",
            data: "{userId:" + userId + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                if (msg.d == "0" || msg.d.length == 0 || msg.d == null) {
                    if (typeof callback == 'function') {
                        callback(null);
                    }
                }
                else if (msg.d <= 0) {
                    if (typeof callback_err == 'function') {
                        callback_err(msg.d, msg, 'GET_CAT_ALL');
                    }
                }
                else {
                    var _data = eval("(" + msg.d + ")");
                    if (typeof callback_err == 'function' && _data[0] != null && typeof _data[0].ErrorCode != 'undefined') {
                        callback_err(_data, msg, 'GET_CAT_ALL');
                    }
                    else if (typeof callback == 'function') {
                        callback(_data);
                    }
                }
            },
            error: function (msg) {
                if (typeof callback_err == 'function') {
                    callback_err(-1, msg, 'GET_CAT_ALL');
                }
            }
        });
    }
    catch (err) {
        if (typeof callback_err == 'function') {
            callback_err(-2, err, 'GET_CAT_ALL');
        }
    }
},
4

1 回答 1

0

This means that your subject to the Cross Side restrictions put in place by your browser. Consider using JSONP if you can to try and get around this issue or if you can guarentee your users are using more up to date browsers you could get around it by using headers on your webserver. Have a look at the mozilla document about it.

于 2012-07-09T21:53:31.463 回答