Unidentified
Living the Developer Life...
- Jun 19, 2012
- 144
- 20
I am trying to update a record in the database with ajax so the page does not reload and it is not posting anything, the php works on its own but not with this ajax :/
My php which is found in test.php is
Code:
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<Script>
$(document).ready(function(){
$("#submit").click(function(){
var first_name = $("#first_name").val();
$.ajax({
type: "POST",
dataType: "html",
url: "test.php",
data: "first_name"+first_name,
success:function(data){
}
});
})
});
</script>
<form action="" method="post">
<input type="text" class="form-textbox2" id="first_name" size="20" name="first_name">
<button type="submit" id="submit" name="update" class="form-submit-button form-submit-button-black_glass">update</button>
</form>
My php which is found in test.php is
PHP:
<?php
include 'core/init.php';
if( isset($_POST['update']) ) {
try {
$first_name = mysql_real_escape_string($_POST['first_name']);
if( !$first_name ) {
throw new Exception ( '' );
} else {
if( update_first_name($_SESSION['id'], $first_name) ) {
echo 'first name has been updated!';
} else {
throw new Exception ( 'Your first name has been changed successfully .' );
}
}
} catch ( Exception $e ) {
echo $e->getMessage();
}
} else {
echo '';
}
?>