亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么 PHP 看不到來自 ajax js 的值?

為什么 PHP 看不到來自 ajax js 的值?

PHP
胡說叔叔 2023-09-30 15:29:17
當我從 JS 端得到結果時,該值變為 true。但我想將值填充到我的 PHP 文件中,所以我使用了 ajax。當我刪除 PHP 中的 ifisset 函數時,出現“未定義索引”錯誤。HTML 端     <form method="post" onsubmit="return false;"  class="form-inline">     <input type="email" name="email" id="subscriber_email" placeholder="Your E-mail" >     <button type="submit" id="subscribe_newsletter" class="btn newsbox-btn w-       100"onclick="gonder()">Subscribe</button>                                   </form>       <div id="subscribe_message"></div>        <p id="succes" class="mt-30"></p>jS側<script  type="text/javascript">function gonder(){var ad=$("input[name='email']").val();$.ajax({    type:"POST",    url:"myphpfile.php",    data:ad,   // I also tried  {'sendingData':ad} but it doesn't work.    success:function(sonuc){        $("#subscribe_message").html(sonuc);        $("#succes").html(sonuc);               }}) }</script>以及 PHP 端<?php    if(isset($_POST["ad"])){    $x=$_POST["ad"];    echo $x;     }   else{      echo "There is nothing coming from the script.";      }     ?>
查看完整描述

1 回答

?
哈士奇WWW

TA貢獻1799條經驗 獲得超6個贊

您正在發送一個值,但您沒有發送具有該值的密鑰。例如,如果值為123則您只發送123,沒有其他內容。ad所以這不會找到它,因為發送的數據中沒有調用密鑰:

$_POST["ad"]

為值添加一個鍵:

data: { ad: ad }

或者甚至簡單地:

data: { ad }


查看完整回答
反對 回復 2023-09-30
  • 1 回答
  • 0 關注
  • 85 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號