當(dāng)我從 JS 端得到結(jié)果時(shí),該值變?yōu)?true。但我想將值填充到我的 PHP 文件中,所以我使用了 ajax。當(dāng)我刪除 PHP 中的 ifisset 函數(shù)時(shí),出現(xiàn)“未定義索引”錯(cuò)誤。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側(cè)<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."; } ?>
為什么 PHP 看不到來(lái)自 ajax js 的值?
胡說(shuō)叔叔
2023-09-30 15:29:17