我一直在尋找這一點,因爲早上,我無法找出其中的問題是..阿賈克斯不工作的按鈕,點擊
這是javascript/ajax
$('#subscribe').live('click', function(){
rel = $(this).attr("rel");
datas = "topic_id="+rel;
$.ajax({
type: 'POST',
url: 'subscribe.php',
data: datas,
success: function(result){
alert("k");
$(this).val(result);
}
});
});
,這是PHP處理Ajax是被張貼到 「subscribe.php
」
<?php
session_start();
require_once(functions/functions.php);
if(isset($_POST["topic_id"])){
$uid = user_id($_SESSION['username']);
$tid = $_POST["topic_id"];
$qry = "SELECT user_id FROM subscribe WHERE topic_id = $tid";
$rst = mysql_query($qry);
if(!$rst){
$query = "INSERT INTO subscribe (user_id, topic_id) VALUES ($uid, $tid)";
$qry = mysql_query($query);
echo "Subscribed";
}else{
echo "hmmm";
}
}?>
,這是按鈕
<input type="button" value="Subscribe" name="buton" id="subscribe" rel="'.$output["id"].'" />
警報似乎可行,但如果(!$ RST){... 不會使插入查詢不運行所做的更改不會生效,並在數據庫中
請解決您的SQL注入錯誤:) – AlanFoster
現場()被棄用jquery1.7,然後取出後.. –
告訴我在哪裏@AlanFoster – 1baga