下面是我的index.php文件,其中我放了一个简单的表和一个按钮“添加用户”。我想要的功能,我点击按钮和我的user.php这是一个简单的用户详细信息显示在没有刷新页面的同一页面。我差不多完成了它,它显示的形式与我已应用的所有样式除了背景图像。我已经附加了“user.php”。任何解决方案???提前谢谢......
Index.php(带ajax函数):
<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function ajaxFunction()
{
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer Browsers
try
{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e)
{
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4)
{
var ajaxDisplay = document.getElementById('add').innerHTML = ajaxRequest.responseText;
}
}
$("html").load("user.php");
}
</script>
</head>
<body>
<form action="index.php" method="get">
<div id="sb">
<input type="text" name="query" />
<input type="submit" value="Search" />
<input type="hidden" value="1" name="doSearch" />
</div>
<div>
<input id="add" type="button" value="Add User" onclick="ajaxFunction()"/><br></br>
<table id="mytable" class="tablesorter">
<thead>
<tr>
<th>Id</th>
<th>Username</th>
<th style="width: 300px; size: 30">Email</th>
<th>Gender</th>
<th>DOB</th>
<th>Country</th>
<th>State</th>
<th>Hobbies</th>
<th>EDIT </th>
<th>DELETE</th>
</tr>
</thead>
user.php的:
<html>
<head>
<title>Registration Page</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<link rel="stylesheet" href="css/main.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="js/statecountry.js"></script>
<script src="js/validation.js"></script>
<script>
$(function() {
$("#datepicker").datepicker({changeMonth: true,
changeYear: true,
yearRange: "-100:+0",
dateFormat: "dd-mm-yy"});
});
</script>
</head>
<body class="container">
<div >
<?php
if(isset($_GET['usid']))
{
if ($_GET['usid']!='')
{
echo'<form action="con-edit-user.php?userid='.$row["u_id"].'" id="form_register" method="post" enctype="multipart/form-data" >';
}
}
else
{
echo '<form action="con_user.php" id="form_register" method="post" enctype="multipart/form-data" >';
}
?>
<input type="hidden" name="userid" value="<?php if(isset($userid)){echo($userid);} ?>">
<div>
<h2>Fill in your details...</h2>
</div>
<table align="left" cellspacing="20px">
<tr>
<td><label>Username :</label></td>
<td><input class="in" id="uname" type="text" name="fname" value="<?php if(isset($row['u_name'])) echo($row['u_name']); ?>"></td>
<td id="nameerror"></td>
</tr>
<tr>
<td><label>Email :</label></td>
<td><input class="in" id="email" type="text" name="email" value="<?php if(isset($row['u_email'])) echo($row['u_email']); ?>">
<?php
if(isset($_GET['err']))
{
if($_GET['err']=="msg")
{
echo'<span id="err">
User already exist, please try different email.
</span>';
}
}
?>
</td>
<td id="emailerror"></td>
</tr>
<tr>
<td><label>Password :</label></td>
<td><input type="password" name="pwd" class="in" id="pwd" value="<?php if(isset($row['u_password'])) echo($row['u_password']); ?>"></td>
<td id="pwderror"></td>
</tr>
<tr>
<td><label>Gender :</label></td>
<td class="ched" id="gender"><input type="radio" name="gender" value="M" <?php if(isset($row['u_gen'])) if($row['u_gen']=="M"){echo("checked='checked'");} ?>> Male
<input type="radio" name="gender" value="F" <?php if(isset($row['u_gen'])) if($row['u_gen']=="F"){echo("checked='checked'");} ?>> Female
</td>
<td id="gendererror"></td>
</tr>
<tr>
<td><label>DOB :</label></td>
<td><input id="datepicker" type="text" name="bdate" value="<?php if(isset($row['u_dob'])) echo($row['u_dob']); ?>"></td>
<td id="dateerror"></td>
</tr>
<tr>
<?php
$sql = "SELECT * FROM country ORDER BY c_name";
$query = mysqli_query($con, $sql);
?>
<td><label>Country :</label></td>
<td><select name="country" class="country" selected="selected">
<option value="select">-------------------Select------------------</option>
<?php while ($row1 = mysqli_fetch_array($query)) { ?>
<option value="<?php echo $row1["country_id"]; ?>" <?php if($row1["country_id"] == $row['u_country']){ echo "selected=selected"; } ?> ><?php echo $row1["c_name"]; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<?php
$sql = "SELECT * FROM states ORDER BY s_name";
$query = mysqli_query($con, $sql);
?>
<td><label>State :</label></td>
<td><select name="state" class="state" selected="selected">
<option value="select">-------------------Select------------------</option>
<?php while ($row1 = mysqli_fetch_array($query)) { ?>
<option value="<?php echo $row1["state_id"]; ?>" <?php if($row1["state_id"] == $row['u_state']){ echo "selected=selected"; } ?> ><?php echo $row1["s_name"]; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td><label>Hobbies :</label></td>
<td class="ched" id="hobbies">
<?php
$hobby = explode(" ",$row['u_hobby']);
?>
<input type="checkbox" name="hobby1" value="C" <?php if(in_array("C",$hobby)) { ?> checked="checked" <?php } ?> <?php if(isset($_POST['hobby1'])){
$check1='selected'; echo $check1; } ?> <?php if($row['u_hobby']=="C"){echo("checked='checked'");} ?> >Cricket
<input type="checkbox" name="hobby2" value="F" <?php if(in_array("F",$hobby)) { echo ("checked=checked"); } ?> <?php if(isset($_POST['hobby2'])){
$check2='selected'; echo $check2; } ?> <?php if($row['u_hobby']=="F"){echo("checked='checked'");} ?>>Football
<input type="checkbox" name="hobby3" value="LM" <?php if(in_array("LM",$hobby)) { echo ("checked=checked"); } ?> <?php if(isset($_POST['hobby3'])){
$check3='selected'; echo $check3; } ?> <?php if($row['u_hobby']=="LM"){echo("checked='checked'");} ?>>Listening Music
</td>
<td id="hobbieserror"></td>
</tr>
<tr>
<td><label>About you :</label></td>
<td><textarea name="desc" rows="4" cols="32"></textarea></td>
</tr>
<tr>
<td><label>Image :</label></td>
<td><input type="file" name="image"></td>
<td><div>
<?php
if(isset($row['u_img']))
{
echo"<img src='".$row['u_img']."'> ";
}
?>
</div></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" name="submit" value="Submit" id="btn">
<input type="reset" value="Reset" id="btn">
<a href="index.php"><input type="button" value="Cancel" id="btn"></a>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>