我与我的数据库连接,我的数据库发给我一些整数值,如“1”,“2”或类似的东西。例如,如果我的数据库发送给我“3”我显示第三页,它正在工作,但我的问题是当它显示第三页时它不会隐藏我当前的页面。我认为我的代码在某处错了。请帮助我
<script>
function show(shown, hidden) {
console.log(shown,hidden)
$("#"+shown).show();
$("#"+hidden).hide();
}
$(".content-form").submit(function(){
var intRowCount = $(this).data('introwcount');
var exec = 'show("Page"+data.result,"Page' + intRowCount + '")';
ajaxSubmit("/post.php", $(this).serialize(), "", exec,"json");
return false;
})
function ajaxSubmit(urlx, datax, loadingAppendToDiv, resultEval, dataTypex, completeEval) {
if (typeof dataTypex == "undefined") {
dataTypex = "html";
}
request = $.ajax({
type: 'POST',
url: urlx,
dataType: dataTypex,
data: datax,
async: true,
beforeSend: function() {
$(".modalOverlay").show();
},
success: function(data, textStatus, jqXHR) {
//$("div#loader2").remove();
loadingAppendToDiv !== "" ? $(loadingAppendToDiv).html(data) : "";
if (typeof resultEval !== "undefined") {
eval(resultEval);
} else {
//do nothing.
}
},
error: function() {
alert('An error occurred. Data does not retrieve.');
},
complete: function() {
if (typeof completeEval !== "undefined") {
eval(completeEval);
} else {
//do nothing.
}
$(".modalOverlay").hide();
}
});
}
</script>
答案 0 :(得分:1)
感谢您帮助我的代码正常工作。问题是由于缓存而发生的。当我清除谷歌浏览器上的缓存和cookie时,它已修复。
答案 1 :(得分:0)
传递给show()方法的第二个参数有点不对:
"Page' + intRowCount + '"
也许你的意思是:
'Page' + intRowCount
编辑:等待你将一串代码传递给ajaxSubmit?里面发生了什么?
如果ajaxSubmit可以使用回调,请尝试:
var exec = function(data) {
show('Page' + data.result, 'Page' + intRowCount);
};
答案 2 :(得分:0)
假设你的html是:
<div id='Page1'>..</div>
<div id='Page2'>..</div>
<div id='Page3'>..</div>
为每个div添加一个类(使用合理的名称,mypage只是一个例子)
<div id='Page1' class='mypage'>..</div>
<div id='Page2' class='mypage'>..</div>
<div id='Page3' class='mypage'>..</div>
传递您要显示的页码并隐藏所有其他,即:
function showmypage(pageselector) {
$(".mypage").hide();
$(pageselector).show();
}
然后将'exec'更改为:
var exec = 'showmypage("#Page"+data.result)';
如果我建议你不删除eval
,那将是我的疏忽,所以不要:
var exec = "..."
使用函数:
var onsuccess = function() { showmypage("#Page"+data.result); };
function ajaxSubmit(..., onsuccess, ...)
{
...
success: function(data) {
onsuccess();
}
}