我有問題,使用php/ajax/mysql傳遞2個參數。PHP Ajax GET方法不會觸發
不能追蹤出了問題
這裏是Ajax代碼
<script type="text/javascript"src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function(){
$('#myonoffswitch').click(function(){
var myonoffswitch=$('#myonoffswitch').val();
if ($("#myonoffswitch:checked").length == 0)
{
var a=myonoffswitch;
}
else
{
var a="off";
}
$.ajax({
type: "POST",
url: "process.php",
data: "ps="+a ,
success: function(html){
$("#display").html(html).show();
}
});
});
});
</script>
<script type="text/javascript">
$(document).ready(function(){
$(".cb-enable").click(function(){
var parent = $(this).parents('.switch');
$('.cb-disable',parent).removeClass('selected');
$(this).addClass('selected');
$('.checkbox',parent).attr('checked', true);
});
$(".cb-disable").click(function(){
var parent = $(this).parents('.switch');
$('.cb-enable',parent).removeClass('selected');
$(this).addClass('selected');
$('.checkbox',parent).attr('checked', false);
});
});
</script>
PHP:
$k=1;
while($row = mysqli_fetch_array($result)) {
$id = $row['ID'];
$ps = $row['Status'];
echo "<div class=\"onoffswitch\">\n";
echo "<input type=\"checkbox\" name=\"$k\" class=\"onoffswitch-checkbox\" id=\"$k\"\n";
if($ps=="1") {
echo "checked ";
}
echo ">";
echo "<label class=\"onoffswitch-label\" for=\"$k\">\n";
echo " <div class=\"onoffswitch-inner\"></div>\n";
echo " <div class=\"onoffswitch-switch\"></div>\n";
echo "</label>\n";
echo "</div>\n";
$k++;
}
過程.PHP是類似於下面:
$ PS = $ _POS [ 'PS']; $ id = $ _ POS ['id'];
//的mysql_query( 「UPDATE TBL設置狀態= '$ PS',其中ID = $ ID」); //不起作用
的mysql_query( 「UPDATE TBL設置狀態= '$ PS',其中ID = 1」);
代碼更新,並僅使1參數/參數時的工作。
POST或GET方法都會好的。請幫忙嗎?
編輯你的問題,而不是寫評論 – Sal00m 2014-11-05 08:02:38
請確保你的代碼是正確縮進,否則它只是不可讀 – 2014-11-05 08:06:19
更新代碼 – 2014-11-05 08:09:03