Lets say you want to check if your query successfuly executed.
The javascript JQuery whould be like this :
$.ajax({
type: "POST",
url: "./update.php",
data : {
'id' : $("#id").val() },
success: function(data)
{
var obj = jQuery.parseJSON(data);
alert(obj[0].result);
}
});
And the PHP script of update.php like this :
include "./includes/database.php";
if (mysql_query("select id from table where id = '".$_POST['id']."'"))
{
$return[] = array('result' => 'id exists');
}
else
{
$return[] = array('result' => 'id not found');
}
echo json_encode($return);
PHP JQuery Mysql Tips
PHP Jquery Mysql website programming tips coding
Tuesday, October 1, 2013
Tuesday, September 24, 2013
JQuery weird bug variable not null after load() called
Today my web based application did something weird, the variable in div element doesnt nulled after load().
<div id = "content">
<input type = "text" id = "name">
<input type = "button" id = "submit">
</div>
$(document).ready(function(){
$("#submit").click(function(){
$("#content").load("./part/add_name.php", {
'name' : $("#name").val()
});
});
});
You can still get value name input after load() to content div.
Possible solution is always call empty.
Example :
$("#content").empty().load("./part/add_name.php", {
'name' : $("#name").val()
});
<div id = "content">
<input type = "text" id = "name">
<input type = "button" id = "submit">
</div>
$(document).ready(function(){
$("#submit").click(function(){
$("#content").load("./part/add_name.php", {
'name' : $("#name").val()
});
});
});
You can still get value name input after load() to content div.
Possible solution is always call empty.
Example :
$("#content").empty().load("./part/add_name.php", {
'name' : $("#name").val()
});
Subscribe to:
Posts (Atom)