时间:2021-07-01 10:21:17 帮助过:7人阅读
思路分析:第一步:兼容IE9,firefox,Opera,Safari等浏览器;
第二步:兼容IE6-8:由于ie6-8 不能修改iframe的name属性
综合解决办法:
function ajaxpost(formid, showid, waitid, showidclass, submitbtn, recall) { var waitid = typeof waitid == 'undefined' || waitid === null ? showid : (waitid !== '' ? waitid : ''); var showidclass = !showidclass ? '' : showidclass; var ajaxframeid = 'ajaxframe'; var ajaxframe = $(ajaxframeid); var formtarget = $(formid).target; var handleResult = function() { var s = ''; var evaled = false; showloading('none'); try { s = $(ajaxframeid).contentWindow.document.XMLDocument.text; } catch (e) { try { s = $(ajaxframeid).contentWindow.document.documentElement.firstChild.wholeText; } catch (e) { try { s = $(ajaxframeid).contentWindow.document.documentElement.firstChild.nodeValue; } catch (e) { s = '内部错误,无法显示此内容'; } } } if (s != '' && s.indexOf('ajaxerror') != -1) { evalscript(s); evaled = true; } if (showidclass) { $(showid).className = showidclass; if (submitbtn) { submitbtn.disabled = false; } } if (!evaled && (typeof ajaxerror == 'undefined' || !ajaxerror)) { ajaxinnerhtml($(showid), s); } ajaxerror = null; if ($(formid)) $(formid).target = formtarget; if (typeof recall == 'function') { recall(); } else { eval(recall); } if (!evaled) evalscript(s); ajaxframe.loading = 0; $('append_parent').removeChild(ajaxframe); }; if (!ajaxframe) { try { ajaxframe = document.createElement(''); } catch (e) { ajaxframe = document.createElement('iframe'); ajaxframe.name = ajaxframeid; ajaxframe.id = ajaxframeid; } ajaxframe.style.display = 'none'; ajaxframe.loading = 1; $('append_parent').appendChild(ajaxframe); } else if (ajaxframe.loading) { return false; } _attachEvent(ajaxframe, 'load', handleResult); showloading(); $(formid).target = ajaxframeid; $(formid).action += '&inajax=1'; $(formid).submit(); return false;}
< 上一篇
JQuery以JSON方式提交数据到服务端示例代码_jquery
下一篇 >
通过JQuery将DIV的滚动条滚动到指定的位置方便自动定位_jquery
记住我的登录 忘记密码?
登录
我已阅读用户协议及版权声明
注册