简体   繁体   English

远程服务器子域上的asp.net Web服务的Jquery Ajax方法错误

[英]Jquery Ajax method error with asp.net web service on a remote server subdomain

I created a project, it is an asp.net project and it has a Service1.asmx and ı hosted this project to remote server like a subdomain ( myservice.test.com/Service1.asmx ) and ı am calling this web service from an asp.net application with jquery ajax method. 我创建了一个项目,它是一个asp.net项目,它有一个Service1.asmx,并且ı将该项目托管到了像子域( myservice.test.com/Service1.asmx )这样的远程服务器上,并且ı正在从使用jquery ajax方法的asp.net应用程序。 This application is on same remote server and ı hosted it like a subdomain ( admin.test.com ) when ı call admin.test.com/Default.aspx (this page uses web service abow) it is giving an error for this error ı looked with chrome console and it says: * (is not allowed by Access-Control-Allow-Origin.) *4444 此应用程序位于同一远程服务器上,并且在ı调用admin.test.com/Default.aspx(此页面使用网络服务)时,像子域( 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');
        }
    }
},

This means that your subject to the Cross Side restrictions put in place by your browser. 这意味着您受制于浏览器对Cross Side的限制。 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. 如果可以尝试解决此问题,或者可以确保用户使用的是最新的浏览器,则可以考虑使用JSONP,您可以使用网络服务器上的标头来解决它。 Have a look at the mozilla document about it. 看看有关它的mozilla文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM