Home  >  Article  >  Backend Development  >  Discuz Uchome ajaxpost小技巧_php技巧

Discuz Uchome ajaxpost小技巧_php技巧

WBOY
WBOYOriginal
2016-05-17 09:21:51905browse

比如默认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