我嘗試搜索,但沒有答案就像我想要的..好吧在這裏我的問題。從其他PHP呼叫DIV頁
我有一個名爲index.php的登錄頁面,裏面的index.php有登錄信息的div。
的index.php
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<script type="text/javascript" src="js/login.js"></script>
<title></title>
</head>
<body>
<form method="POST">
<p>Username <input type="text" name="cUsername" size="20"></p>
<p>Password <input type="text" name="cPassword" size="20"></p>
<p><input type="submit" value="Login" name="B1"></p>
</form>
<div id="msg"></div>
</body>
</html>
,在這裏我jQuery的,如果不刷新頁面登錄。
login.js
$(document).ready(function() {
$('#Loading4').hide();
});
function ajax-login(){
var cUusername = $("#cUsername").val();
var password = $("#password").val();
if(cUsername.length > 2){
$('#Loading4').show();
$.post("login.php", {
cUsername: $('#cUsername').val(),
password: $('#password').val(),
}, function(response){
$('#Info4').fadeOut();
$('#Loading4').hide();
setTimeout("finishAjax4('Info4', '"+escape(response)+"')", 450);
});
return false;
}
}
function finishAjax4(id, response){
$('#'+id).html(unescape(response));
$('#'+id).fadeIn(1000);
}
,在這裏我稱之爲登錄頁面
的login.php
<?php
if($_REQUEST)
{
$username = $_REQUEST['username'];
$query = "select * from tbl_user where username = '".strtolower($username)."'";
$results = mysql_query($query) or die('Error to connect to the database');
if(mysql_num_rows(@$results) > 0) // not available
{
echo '<div id="msg">Login Successful !</div>';
}
else
{
echo '<div id="msg">Not Register Yet !</div>';
}
}?>
我的意思是,我想顯示消息的成功或失敗「 login.php「呼叫ID爲msg的DIV位於」index.php「文件中的DIV。在index.php中將顯示使用ajax登錄時成功或失敗時顯示。但是我想從login.php頁面調用這個DIV。
我可以這樣做嗎?謝謝
*旁註: *停止使用不推薦的'mysql_ *'函數。改用MySQLi或PDO。 – Raptor