跨域Web服务 [英] Cross Domain Webservice
本文介绍了跨域Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Jquery调用我的webservice(跨域服务)。
但$ .support.cors = true;在IE8中运行正常,但在chrome和firefox中没有。
请帮我解决这个问题。
Hi,
I am trying to call my webservice (cross domain service) using Jquery.
But $.support.cors = true; is working fine in IE8 , but not in chrome and firefox.
Please help me to resolve this issue.
<script src= "jquery-1.9.1.js"></script>
<script src ="jquery-1.9.1.min.js"></script>
<script language ="javascript" type="text/javascript">
function Do() {
$.support.cors = true;
$.ajax({
type: "Get",
url: "url", // Location of the service
data: '{"parameter"="value"}', //Data sent to server
contentType: "application/json;charset-uf8", // content type sent to server
dataType: "xml", //Expected data format from server
success: function(msg) {
//Implement get data from service as you wish
alert("Success");
},
error: function(err) {
// When Service call fails
alert("error");
}
});
}
</script>
[从答案框中移出]
即使我尝试从同一个域访问数据,我也会遇到同样的错误。
[Moved From Answer Box]
I am getting same error, even when i try access the data from the same domain.
function Do() {
$.support.cors = true;
$.ajax({
type: "GET",
url: "test.xml",
dataType: "xml",
data: "",
headers: { 'Accept': 'text/xml' },
headers: { 'Access-Control-Allow-Headers': 'application/json; charset=utf-8' },
error: function(xml) { alert(xml.text); },
success: function(xml) {
alert("success");
spnid.innerHTML = xml.text;
}
});
}
推荐答案
.support.cors = true;在IE8中运行正常,但在chrome和firefox中没有。
请帮我解决这个问题。
.support.cors = true; is working fine in IE8 , but not in chrome and firefox.
Please help me to resolve this issue.
<script src= "jquery-1.9.1.js"></script>
<script src ="jquery-1.9.1.min.js"></script>
<script language ="javascript" type="text/javascript">
function Do() {
.support.cors = true;
.support.cors = true;
.ajax({
类型:获取,
url:url,//服务的位置
数据:'{参数= value}',//发送到服务器的数据
contentType:application / json; charset-uf8,//发送到服务器的内容类型
dataType:xml,// Ex来自服务器的数据格式
success:function(msg){
//实现从服务中获取数据,因为你希望
alert(成功);
},
错误:函数(错误){
//当服务调用失败时
alert(error);
}
});
}
< / script >
.ajax({ type: "Get", url: "url", // Location of the service data: '{"parameter"="value"}', //Data sent to server contentType: "application/json;charset-uf8", // content type sent to server dataType: "xml", //Expected data format from server success: function(msg) { //Implement get data from service as you wish alert("Success"); }, error: function(err) { // When Service call fails alert("error"); } }); } </script>
[从答案框中移出]
即使我尝试从同一个域访问数据,我也会遇到同样的错误。
[Moved From Answer Box]
I am getting same error, even when i try access the data from the same domain.
function Do() {
这篇关于跨域Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文