index.php:
窗体在引导模式中。
<form class="form-horizontal" action="core/login.php" method="post">
...
</form>
core/login.php:
if($conn){
...
if ($count > 0) {
...
}
else { echo "Login Failed"; }
oci_free_statement($stid);
oci_close($conn);
}
如何将echo发送回与index.php
的登录表单相同的Bootstrap模式?
if($conn){
...
if ($count > 0) {
...
}
else {
header("Location: index.php?error=loginauth");
exit;
}
oci_free_statement($stid);
oci_close($conn);
}
然后在index.php中,您可以返回错误参数并切换它:
index.php
<?
if(isset($_GET['error']))
{
if($_GET['error']=='loginauth')
{
echo "Login failed";
}
if($_GET['error']=='error2')
{
echo "error 2 description";
}
}
?>
使用jquery.ajax((或.Post((发布数据
首先,您必须使用jquery:从表单中获取数据
var form_values = {
value_name1 : $('#selector1').val(),
value_name2 : $('#selector2').val()
};
然后使用$.post((将数据发送到处理php脚本,php脚本应返回json_encode:的json格式的验证消息
$.post('/url/path', form_values, callback(data));
callback((函数将保存您的代码后调用完成后发生的情况,无论是失败还是成功:
function callback(data)
{
//Decode received message with JSON.parse if it is available or $.parseJSON if not
data = JSON && JSON.parse(data) || $.parseJSON(data);
//Check message variable received from php
if (data.message == "Login Failed")
{
//Do whatever you want here, I`ve used alert to be simpler
alert('Failed to login');
} else {
alert('Succesfully logged in');
}
}
在模态中使用ajax。jQuery.ajax();
Plunker示例http://embed.plnkr.co/ThNNWFlvbnG6qFwrSd97/preview