I have written JQuery code for something and at the end of the JQuery, I have written the code for stopping form redirection. My Partial code is as:-
Jquery Code is as and file name is JScript/newdep.js
$("#submit").click( function(){
$.post($("#form_ndep").attr("action"),
$("#form_ndep:input").serializeArray(),
function(info){
$("#error_div").empty();
$("#error_div").html(info);
});
$("#form_ndep").submit(function() {
return false;
});
});
PHP code is as with file name newdepartment.php
<?php
session_start();
if(!$_SESSION['sessionusername'])
{
header("location:index.php");
}
else
{
include ('connection2.php');
$local_session = $_SESSION['sessionusername'];
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<link rel="stylesheet" media="screen" href="css/master.css">
<link rel="stylesheet" media="screen" href="css/menus.css">
<link href="CSS/pstyle.css" rel="stylesheet" type="text/css" media="all" />
<script type="text/javascript" src="JScript/jquery-1.9.1.js"> </script>
<script type="text/javascript" src="JScript/newdep.js"></script>
<title>Phytec India</title>
</head>
<body>
<div id="welcome">
<div id="welcome_text">Welcome <?php echo "$local_session" ?> <a href="logout.php">Signout</a></div>
</div>
<div id="header">
<div id="header_logo">
<img src="Images/logo.gif" height="29" width="178" />
</div>
</div>
<div id="container">
<div id="departments"><div id="heading_text">Add New Department</div>
<!-- <div id="error_div">
</div>-->
</div>
<div id="wrap2">
<p class="validate_msg">Please fix the errors below!</p>
<form method="POST" action="PHP/newdep.php" id="form_ndep">
<p> <label for="dep_id">* Department Id :</label> <input name="txtid_depid" type="text" placeholder="Department Id" /> <span class="sdepid"></span> </p>
<p> <label for="dep_name">* Deparment Name :</label> <input name="txtname_depname" type="text" placeholder="Department Name" /> <span class="sdepname"></span> </p>
<input type="submit" id="submit" value="Save">
</div>
</form>
<div id="error_div">
</div>
</div>
<!--<table width="998px" cellspacing="0" cellpadding="0" border="none">
</table>
-->
</div>
</body>
</html>
another php code with file name PHP/newdep.php:-
<?php
include('../connection2.php');
$lcl_depid = mysql_real_escape_string($_POST["txtid_depid"]);
$lcl_depname = mysql_real_escape_string($_POST["txtname_depname"]);
$query = "INSERT INTO table_mstr_department (DeptId, DeptName) VALUES ('$lcl_depid','$lcl_depname')";
if(mysql_query($query))
{
echo "Insertion Successfull!";
}
else
{
echo "Insertion Failed!";
}
When i click on the save button it redirects the page from newdepartment.php to PHP/newdep.php as i have written the code of this.... Please help me to solve the problem.....