如何使用JavaScript从跨域调用Web Service [英] How to call Web Service from cross-domain using JavaScript
本文介绍了如何使用JavaScript从跨域调用Web Service的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在通过JavaScript从跨域调用Web服务时遇到问题
我的服务托管在http:/abc.com/mywebservice.asmx/helloword
如果我从http:/abc.com/default.html调用我的网络服务,那么它正在工作
但如果我打电话给我的网络服务表格另一个域名如httpp:/bcd.com/form.html然后它不起作用并给我错误
我的ajax调用: -
I have a Problem on calling web service From Cross Domain By JavaScript
My Service is hosted at "http:/abc.com/mywebservice.asmx/helloword"
and if i call my web service from from "http:/abc.com/default.html " then it is working
but if i call my web service form another domain like httpp:/bcd.com/form.html then it is not working and giving me error
my ajax call:-
$.ajax({
type: "POST",
url: "http:/abc.com/mywebservice.asmx/helloword",
data: {},
cache: false,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response) {
Game._onSessionGot(response.d);
}
});
请帮帮我
推荐答案
.ajax({
type:< span class =code-string> POST,
url: http:/abc.com/mywebservice.asmx/helloword,
data:{},
cache: false ,
contentType: application / json; charset = utf- 8,
dataType: json,
成功: function (response){
Game._onSessionGot(response.d);
}
});
.ajax({ type: "POST", url: "http:/abc.com/mywebservice.asmx/helloword", data: {}, cache: false, contentType: "application/json; charset=utf-8", dataType: "json", success: function(response) { Game._onSessionGot(response.d); } });
请帮帮我
正如这里提到的 [ ^ ],对于跨域Web服务,您可以使用JSONP。
参考: JSON和JSONP [ ^ ]
示例实现:跨域JSONP与jQuery调用循序渐进指南 [ ^ ]
总的来说,建议将请求地址放在脚本标签中,然后在需要时解析内容。
另一篇相同的详细文章:呼叫Cross Do AJAX中的主要Web服务 [ ^ ]
As mentioned here[^], for cross domain webservice you can use JSONP.
Refer: JSON and JSONP[^]
Example implementation: Cross-domain JSONP with jQuery call step-by-step guide [^]
Overall, it suggests, to place the requesting address in the script tag, and then parse the content when needed.
Another detailed article on the same: Calling Cross Domain Web Services in AJAX[^]
这篇关于如何使用JavaScript从跨域调用Web Service的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文