我有一个弹出的div,它要求输入用户名和密码,当用户提交表单时,我使用ajax调用php文件来对数据库进行验证。现在的问题是,在ajax调用后,我无法保留相同的弹出窗口和相同的页面。该消息显示在新页面中。有人能帮我吗?
我的ajax调用是这样的:在这里,我对index.php
进行ajax调用,以检索echo/print字符串是否显示在同一弹出窗口上。通常在所有其他文件中,如果不是弹出窗口,我可以得到消息,但在这种情况下发现很困难:
function chk_login()
{
jQuery.ajax({
type: "POST",
url:"index.php",
data: $('#loginForm').serialize(),
success: function(js){
//js is returning a html object I should get that error message instead
if(js!=1){
bootbox.alert(js)
return false;
}
},
error: function(){
alert("Please try again. Server have not sent response.");
}
});
return false;
}
为了在同一弹出窗口上显示消息,在该弹出窗口内进行除数并给它一个id。
例如:<div id="displayMessage"></div>
您必须在弹出分区中创建此分区
现在,我们可以使用上面部分的id,即"显示消息",在弹出窗口中打印服务器响应。
现在您的ajax调用将如下所示:
jQuery.ajax({
type: "POST",
url:"index.php",
data: $('#loginForm').serialize(),
success: function(js){
$("#displayMessage").html(js);/* 'displayMessage' is ID of div which lies inside pop-up & 'js' is our server-side responce */
},
error: function(){
alert("Please try again. Server have not sent response.");
}
});