标签:
利用flash让IE7.8.9ajax支持跨域
废话不多说,直接上核心调用代码
/**
* // 解决IE8下ajax无法跨域的问题 $.flashAjax
$.flashAjax({
flash_id: 'JS_flashProductBooking',
data_type: "text", //text 、json,
page_charset: 'gb2312', //gb2312 、utf-8,
debug: false,
url: ajxa_url,
data: '',
type: 'GET',
success: function (data) {
// todo...
}
});
*/
$.extend({
flashAjax: function (setting) {
var JS_flashAjax = null;
var userAgent = window.navigator.userAgent.toLowerCase();
if(userAgent.indexOf("msie 9.0")>0 || userAgent.indexOf("msie 8.0")>0 || userAgent.indexOf("msie 7.0")>0) {
if(typeof window.SWFLwkPost == 'undefined') {
loadSWFPost(initSWFPost);
}else {
initSWFPost();
}
function initSWFPost() {
try {/*在低版本IE下*/
/*var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");不报错表示支持flash*/
var _flashBtn = document.createElement('div');
_flashBtn.id = setting.flash_id || '_flashAjaxBtn';
_flashBtn.style.display="none";
document.getElementsByTagName('body')[0].appendChild(_flashBtn);
JS_flashAjax = new SWFLwkPost({
button_height:1,
button_width:1,
data_type:setting.data_type || 'json', /*text、json*/
page_charset:setting.page_charset || 'utf-8',/*gb2312、utf-8*/
/*打开调试开关*/
debug: setting.debug || false,
/*flash地址*/
flash_url: "/ext/swflwkpost/swflwkpost.swf",
/*请求URL地址*/
upload_url:setting.url || '',
/*FLASH 载入位置ID*/
button_placeholder_id: setting.flash_id || '_flashAjaxBtn',
upload_complete_handler: function (data) {
if(setting.success){
setting.success(data);
}
},
flashready:false
});
setTimeout(function () {
JS_flashAjax.postAddParamData((setting.data || ''));/*传表单序列化字符串对象*/
JS_flashAjax.postSend();
},400);
} catch (e) {/*低版本IE且不支持flash*/
}
}
function loadSWFPost(callback) {
var swfpost = document.createElement("script");
swfpost.type = "text/javascript";
swfpost.charset = "utf-8";
swfpost.src = '/ext/swflwkpost/swflwkpost.js';
if(typeof swfpost.onload == 'undefined') {
swfpost.onreadystatechange = function () {
var r = swfpost.readyState;
if (r === 'loaded' || r === 'complete') {
swfpost.onreadystatechange = null;
callback();
}
};
} else {
swfpost.onload = function(){
callback();
}
}
var head = document.getElementsByTagName('head')[0];
var s = head.getElementsByTagName("script")[0];
if(s == undefined) {
if (head != undefined) {
head.appendChild(swfpost);
}
} else {
s.parentNode.appendChild(swfpost);
}
}
}else {
$.ajax(setting);
}
}
});
依赖文件(/ext/swflwkpost/*)
标签:
来源: /liguanjie8/article/details/85245815
如果觉得《ie7+ajax跨域 利用flash让IE7.8.9ajax支持跨域》对你有帮助,请点赞、收藏,并留下你的观点哦!