如何使用jquery,ajax?
更新datebase中的数据这是我的数据库查询:
UPDATE news SET visited = 1 WHERE id=$id
点击网址后,我想将值从0更改为1.
我的尝试:
$('a').bind('click', function(){
$.ajax...
});
答案 0 :(得分:1)
使用jquery提交表单,
$.post('yourfile.php',$("#yourformname").serialize()+'&ajax=1', function(data){
write in relevant messages after updating.
}
然后在yourfile.php中,进行必要的更新。
答案 1 :(得分:0)
$('#formSubmit').click(function(){
$.post("callpage.php",{"news":"somenews","visit":"somevisit"},function(d){ if(d==1){ alert('Form Submitted Successfully'); } else{ alert('There's some error please try again later'); }});
});
<强> callpage.php 强>
if(!empty($_POST)){
$news = isset($_POST['news'])?mysql_real_escape_string($_POST['news']):"";
$visit = isset($_POST['visit'])?mysql_real_escape_string($_POST['visit']):"";
if(mysql_query("INSERT INTO `table_name` (`news`,`visit`) VALUES('".$news."','".$visit."')")){
echo "1";
} else echo "0";
} else echo "0";