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

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

無法在 AJAX 中提取 PHP 信息

無法在 AJAX 中提取 PHP 信息

慕妹3242003 2023-04-14 17:24:56
索引.php →    <form>          <div class="form-group">        <!-- <input type="text" id="name" class="form-control" placeholder="Enter Name"> -->    </div>    <div class="form-group">        <button type="button" class="btn btn-success" id="btn">Click me I am Neo Anderson</button>    </div></form><div id="message"></div><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script><script>    $(document).ready(function(){           $("#btn").click(function(){            $.post("ajax.php",function(response){                // alert(response);                var message = $("#message").val();                message.html(response);                     })            .fail(function(error){                alert(error.StatusText);            })        })          })      </script>和 ajax.php →    <?php echo "The ajax post is working";問題:我無法在我的 ajax 請求中從 ajax.php 文件中獲取打印材料。我在哪里步履蹣跚?
查看完整描述

3 回答

?
catspeake

TA貢獻1111條經驗 獲得超0個贊

你這里有問題:

var message = $("#message").val();

將那行代碼替換為:

var message = $("#message");

您不想獲取 #message div 的值,所以不要使用val()方法。


查看完整回答
反對 回復 2023-04-14
?
溫溫醬

TA貢獻1752條經驗 獲得超4個贊

$("#message").html(響應);

    //or

var message = $(“#message”);

message.html(響應);


查看完整回答
反對 回復 2023-04-14
?
慕勒3428872

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

 $(document).ready(function(){   

    $("#btn").click(function(){

        let message = $("#message").val();

        $.post("ajax.php",{

         msg: message

        },

        function(response){

            // alert(response);

            message.html(response);         

        },"json")

    })      

})

為 JavaScript 試試這個。對于 ajax.php 文件試試這個:


<?php 

echo json_encode("The ajax post is working");


查看完整回答
反對 回復 2023-04-14
  • 3 回答
  • 0 關注
  • 146 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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