简体   繁体   中英

error while calling asmx file through jquery

When i am trying to access the services in the same solution the webservice is returning me the result. But when i upload this webservice and trying to access then is giving the error.

  var _postData = '{lat:"42.28684519999999",lang:"-83.05254932"}';
        $.ajax({
            url: 'http://geo.xyz.com/Service.asmx/GetGeoLocationListByLatLang',
            data: _postData,
            type: "POST",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                alert(data.d);
                //                    $.each(data, function (i, item) {

                //                        alert(i);
                //                    });
                //Result(data);
                //                    alert(data.d);
                //                    var obj = $.parseJSON(data.d);
                //                    alert(obj);
            },
            error: function (request, status, error) {
                alert(request.responseText);
                alert(error);
                alert(status);
            }
        });

You are violating the same origin policy restriction that's built-in browsers and which prevents you from sending cross domain AJAX requests. Here's a nice guide which covers different possible workarounds. But since you need to use POST your choices are very limited at this stage. I guess that a server side proxy on your domain serving as a bridge and delegating the call to the remote domain would be the best solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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