使用Jquery在Asp.net中调用跨域WebService [英] Cross Domain WebService Call in Asp.net using Jquery

查看:138
本文介绍了使用Jquery在Asp.net中调用跨域WebService的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





要求是:

a)webservice(假设Webservice.asmx)托管在一台服务器上,假设www.xyz .com

b)在www.xyz.com域上,存在访问此Web服务的javascript文件。

c)在www.test.com上,www的javascript文件.xyz.com包含在html页面中。

d)当我运行www.test.com网站的html页面时,我得到了jquery解析错误。

e)当我包括在www.xyz.com域的html页面中相同的javascript文件然后它工作正常。

f)这两个应用程序都在IIS6.0上运行



我使用jQuery与jsonp一起实现它。



Hi,

Requirement is:
a) webservice(Suppose Webservice.asmx) is hosted on one server, suppose www.xyz.com
b) On www.xyz.com domain, a javascript file is present who accesses this webservice.
c) On www.test.com , the javascript file of www.xyz.com is included in html page.
d) When i run html page of www.test.com site, i got jquery parsed error.
e) When i include same javascript file in html page of www.xyz.com domain then it works fine.
f) Both applications are running on IIS6.0

I implemented it using using jquery with jsonp.

var baseurl = "http://localhost:50249/WebService.asmx";
$.support.cors = true;

    $.ajax({
        type: ''POST'',
        //crossDomain: true,
        dataType: "jsonp",
        jsonpCallback: ''jsonCallback'',
        contentType: "application/json; charset=utf-8",
        url: baseurl + "/HelloWorld",
        data: ''{}'',
        dataType: "json",
        success: function(data) {
            alert(data.d);
        },
        error: function(err) {
            alert(err.statusText);
        }
    });





获取 statusText =No Transport。

status = 0


浏览器控制台出现以下错误。

来源http :// localhost:64048不允许使用Access-Control-Allow-Origin。





注意:在IE8它工作正常。



有谁能告诉我如何访问跨域网络服务?



先谢谢。



Getting statusText="No Transport".
status=0

Following Error in browser console.
"Origin http://localhost:64048 is not allowed by Access-Control-Allow-Origin. "


Note: In IE8 it is working fine.

Can anyone please let me know how to access cross domain webservice ?

Thanks in Advance.

推荐答案

.support.cors = true;
.support.cors = true;


.ajax({
type:''POST'',
// crossDomain:true,
dataType:jsonp,
jsonpCallback:''jsonCallback'',
contentType:application / json; charset = utf-8,
url:baseurl +/ HelloWorld,
data:''{}'',
dataType:json,
成功:函数(数据){
alert(data.d);
},
错误:函数(错误){
alert(err.statusText);
}
});
.ajax({ type: ''POST'', //crossDomain: true, dataType: "jsonp", jsonpCallback: ''jsonCallback'', contentType: "application/json; charset=utf-8", url: baseurl + "/HelloWorld", data: ''{}'', dataType: "json", success: function(data) { alert(data.d); }, error: function(err) { alert(err.statusText); } });





获取 statusText =无运输。

status = 0


浏览器控制台中出现以下错误。

Access-Control-Allow-Origin不允许使用原始http:// localhost:64048。





注意:在IE8中工作正常。



任何人都可以告诉我如何访问跨域网络服务吗?



先谢谢。



Getting statusText="No Transport".
status=0

Following Error in browser console.
"Origin http://localhost:64048 is not allowed by Access-Control-Allow-Origin. "


Note: In IE8 it is working fine.

Can anyone please let me know how to access cross domain webservice ?

Thanks in Advance.


这篇关于使用Jquery在Asp.net中调用跨域WebService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆