我希望在Ajax成功函数
之后我可以返回到上一页。
<div id="dialog" title="Complain">
<form id="komenform">
<label>Model :</label>
<input type="text" id="comodel" name="comodel"/>
<label>Komentar :</label>
<textarea id="comment" name="comment" rows="5" cols="20" ></textarea>
<button id="submitcom" type="button" class="ui-state-default ui-corner-all"><span>Submit </span></button>
<input name="action" value="inputcom" type="hidden">
</form>
</div>
$("#komenform").validate({
rules:{
comodel:{
required:true
},
comment:{
required:true
}
}
});
$("#submitcom").click(function() {
if($("#komenform").valid()) {
var params=$("#komenform").serialize();
$.ajax({
type:"post",
url:"/QA/process2.php",
data:params,
cache :false,
async :false,
success : function() {
$("#comodel").val("");
$("#comment").val("");
$("#dialog").dialog('close');
history.back();
},
error : function() {
alert("Data failed to input.");
}
});
}
});
但这行不通。
<小时/>更新
在我尝试删除 dialog('close')
后它起作用了:
success : function() {
$("#comodel").val("");
$("#comment").val("");
// $("#dialog").dialog('close');
window.history.go(-1);
return false;
},
但是,我需要双击提交按钮。为什么?
最佳答案
它有效..
success : function() {
$("#comodel").val("");
$("#comment").val("");
// $("#dialog").dialog('close');
window.history.go(-2);
return false;
},
只需将-1
更改为-2
即可。
关于jquery - History.back() 在 ajax 成功函数后不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18250271/