iT邦幫忙

1

php接收不到ajax給的值

我在index.php內取得了按鈕的id後
使用ajax給php
可是php卻接收不到值
程式如下

index.php

<script src = "https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script>
function update(id) {
    
    alert(id); 
    $.ajax({
    url:"shoppingCart.php",
    type:"POST",
    data: {
        "id": id
    },
    error:function(){
        alert("失敗");
    },
    success:function(){
        alert("成功");
    } 
});

}
</script>

shoppingCart.php

<?php 
$id = $_POST["id"];
echo $id;
?>

謝謝

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

1
㊣浩瀚星空㊣
iT邦大神 1 級 ‧ 2021-05-02 16:56:23
最佳解答

將ERROR的地方。改成這樣

error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
},

然後去查看問題點。

xiao_wen iT邦新手 5 級 ‧ 2021-05-02 18:55:43 檢舉

謝謝你的幫忙,這是我第一次使用ajax,完全看不懂.....

0
混水摸魚
iT邦研究生 2 級 ‧ 2021-05-03 10:15:40

https://www.webteach.tw/?p=297
這個給你參考參考

xiao_wen iT邦新手 5 級 ‧ 2021-05-03 19:14:26 檢舉

非常感謝!!!!

我要發表回答

立即登入回答