Home  >  Article  >  php教程  >  Discuz Uchome ajaxpost小技巧

Discuz Uchome ajaxpost小技巧

WBOY
WBOYOriginal
2016-06-06 20:35:341820browse

discuz的ajaxpost功能有点强大,但缺点也很明显,如果ajaxpost提交一个FORM,那么返回的时候只能显示showmessage的内容,而不会主动跳转,因此这里就有一个小技

比如默认submit按钮这样操作:onclick="ajaxpost('formid')";之类的,我们可以先这样。。
onclick="$('__formid').innerText='';ajaxpost('formid');checkPostResult();";
含义其实很简单,先把ajaxpost提示信息所在的div内容清空。然后提交。最后,根据返回值来判断。。

复制代码 代码如下:


function checkPostResult(){
var cid = setInterval(function(){
if( $('__formid').innerText == 'success'){
alert('提交成功');
location.href='xxxxx.php';
clearInterval(cid);
}
},1000);
}


这个处理也很简单,香港服务器,为什么是用setInterval和clearInterval,主要是由于ajax是异步操作,如果不用setInterval方法 ,那么在ajaxpost结束的时候,香港空间,其实提示信息还没有append到提示信息所在的ID里,所以用setInterval方法先延迟然后循环处理最后再结束提示。。。

clearInterval用的不太对,香港空间,但短时间内想不到更好的。先这样临时解决喽。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn