Sunday, 18 August 2013

Call DIV From other PHP Page

Call DIV From other PHP Page

I try search but nothing answer like what i want.. Okay here my problem.
I have login page called index.php and inside index.php have div for
information login.
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>
and here my Jquery that login without refresh page.
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);
}
and here my login page called
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>';
}
}?>
What i mean is, i want show message success or failed from "login.php"
call DIV with ID msg where that DIV in "index.php" file. in index.php will
show when login using ajax show up when success or failed. But i want call
this DIV from login.php page.
Can i do this? Thank you

No comments:

Post a Comment