如何处理ie8 / 9的Jquery Ajax跨域 [英] what to do for Jquery Ajax cross domain for ie8/9
问题描述
EveryOne
这里是我的代码,它返回webmethod的数据列表。这项工作在chrome,ff和ie10上成功完成,但我可以为ie8 / 9做什么,因为它生成' acesss否认'错误。我需要跨域问题的潜在解决方案。我还必须将数据传递给类似数据的方法:{'countryMasterId':'+ CountryId +'}。
所以plz建议你的想法。[我该怎么办IE8 / 9?]
//
$ .support.cors = true;
// FlightHotel Flyfrom
$ .ajax({
类型:POST,
crossDomain:true,
url:http://test.a1travel.com /WebMethods.aspx/GetFlightHotelSource,
数据类型:json,
//数据:{'countryMasterId':'+ CountryId +'},
contentType:application / json; charset = utf-8,
成功:函数(结果){
FillFlightHotelSource(result.d) );
},
错误:函数(XMLHttpRequest,status,errorThrown){
alert(errorThrown);
}
});
<前lang =cs>函数FillFlightHotelSource(结果){
var ddlFSource = document.getElementById ( ddlFSource);
var ddlSource = document.getElementById( ddlSource跨度>);
if (result!= null ){
for ( var i = 0 ; i < result.length; i ++){
var option = document.createElement( 选项);
option.text = result [i] .sName;
选项。 value = result [i] .scode;
ddlFSource.options。 add (option);
option = document.createElement( option);
option.text = result [i] .sName;
选项。 value = result [i] .scode;
ddlSource.options。 add (option);
}
}
GetFHDestination(ddlSource);
GetFHDestination(ddlFSource);
} .support.cors = true;
// FlightHotel Flyfrom
.ajax({
类型:POST,
crossDomain:true,
url:http://test.a1travel.com/WebMethods.aspx/GetFlightHotelSource,
数据类型:json,
//数据:{' countryMasterId':'+ CountryId +'},
contentType:application / json; charset = utf-8,
success:function(result){
FillFlightHotelSource(result.d);
},
错误:函数(XMLHttpRequest,status,errorThrown){
alert(errorThrown);
}
});
function FillFlightHotelSource(result){
var ddlFSource = document.getElementById( ddlFSource跨度>);
var ddlSource = document.getElementById( ddlSource跨度>);
if (result!= null ){
for ( var i = 0 ; i < result.length; i ++){
var option = document.createElement( 选项);
option.text = result [i] .sName;
选项。 value = result [i] .scode;
ddlFSource.options。 add (option);
option = document.createElement( option);
option.text = result [i] .sName;
选项。 value = result [i] .scode;
ddlSource.options。 add (option);
}
}
GetFHDestination(ddlSource);
GetFHDestination(ddlFSource);
}
有一些方法可以克服跨域请求
< a href =http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin->规避同源策略的方法 [ ^ ]
< a href =http://www.slideshare.net/SlexAxton/breaking-the-cross-domain-barrier> http://www.slideshare.net/SlexAxton/breaking-the-cross-domain-barrier [ ^ ]
有一些工具可以帮助解决跨域请求:
http://net.tutsplus.com/tutorials/javascript-ajax/quick-tip-cross-domain -ajax请求与 - YQL - 和 - 的jquery / [<一个href =http://net.tutsplus.com/tutorials/javascript-ajax/quick-tip-cross-domain-ajax-request-with-yql-and-jquery/target =_ blanktitle =新窗口> ^ ]
http:// james .padolsey.com / javascript / cross-domain-requests-with-jquery / [ ^ ]
Hi,EveryOne
here is my code which return list of data from webmethod .this work succesfully on chrome,ff,and ie10,but what I can do for ie8/9 because it genrate 'acesss denied' error.I need potential solution for cross domain issue. I also have to pass data to a method like data: "{'countryMasterId':'" + CountryId + "'}".
so plz suggest your Idea.[what should I do for IE8/9?]
//
$.support.cors = true;
//FlightHotel Flyfrom
$.ajax({
type: "POST",
crossDomain: true,
url: "http://test.a1travel.com/WebMethods.aspx/GetFlightHotelSource",
datatype: "json",
//data: "{'countryMasterId':'" + CountryId + "'}",
contentType: "application/json; charset=utf-8",
success: function(result) {
FillFlightHotelSource(result.d);
},
error: function(XMLHttpRequest, status, errorThrown) {
alert(errorThrown);
}
});
function FillFlightHotelSource(result) {
var ddlFSource = document.getElementById("ddlFSource");
var ddlSource = document.getElementById("ddlSource");
if (result != null) {
for (var i = 0; i < result.length; i++) {
var option = document.createElement("option");
option.text = result[i].sName;
option.value = result[i].scode;
ddlFSource.options.add(option);
option = document.createElement("option");
option.text = result[i].sName;
option.value = result[i].scode;
ddlSource.options.add(option);
}
}
GetFHDestination(ddlSource);
GetFHDestination(ddlFSource);
}
.support.cors = true;
//FlightHotel Flyfrom
.ajax({
type: "POST",
crossDomain: true,
url: "http://test.a1travel.com/WebMethods.aspx/GetFlightHotelSource",
datatype: "json",
//data: "{'countryMasterId':'" + CountryId + "'}",
contentType: "application/json; charset=utf-8",
success: function(result) {
FillFlightHotelSource(result.d);
},
error: function(XMLHttpRequest, status, errorThrown) {
alert(errorThrown);
}
});
function FillFlightHotelSource(result) { var ddlFSource = document.getElementById("ddlFSource"); var ddlSource = document.getElementById("ddlSource"); if (result != null) { for (var i = 0; i < result.length; i++) { var option = document.createElement("option"); option.text = result[i].sName; option.value = result[i].scode; ddlFSource.options.add(option); option = document.createElement("option"); option.text = result[i].sName; option.value = result[i].scode; ddlSource.options.add(option); } } GetFHDestination(ddlSource); GetFHDestination(ddlFSource); }
There are some ways to overcome the Cross Domain Request
Ways to circumvent the same-origin policy[^]
http://www.slideshare.net/SlexAxton/breaking-the-cross-domain-barrier[^]
There are some tools that help with cross-domain requests:
http://net.tutsplus.com/tutorials/javascript-ajax/quick-tip-cross-domain-ajax-request-with-yql-and-jquery/[^]
http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/[^]
这篇关于如何处理ie8 / 9的Jquery Ajax跨域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!