weixin_33738555 2016-12-19 01:39 采纳率: 0%
浏览 19

Ajax查询不起作用

I have spent some time looking at examples of Ajax, sending a variable to PHP and getting back a different variable. This is from another page (how to get variables from php using AJAX) but it seems something is not working for me. I do not get an error, just no actions appear to happen. My goal is to simply post some data to the php page and get variables back and put them in different DIVs.

htmlpage.html

<html>
<head>
<script>
    $(document).ready(function() {
    $("#ajaxButton").click(function() {
        $.ajax({
            url:'phppage.php',
            data:{username: $('#username').val()},
            type:'POST',
            success: function(data) {
              $('#result').html(data);
            }
        });
    });
});
</script>
</head>
<body>
<input type="text" name="username" id="username"/>
<input type="button" value="Find" id="ajaxButton"/>
<div id="result">This should change on click</div>
</body>
</html>

phppage.php

<?php

$_POST['username'];
$username = $_POST['username'];
$result = '<div class="result">' .$username. "</div>";
echo $result;

?>
  • 写回答

1条回答 默认 最新

  • 撒拉嘿哟木头 2016-12-19 01:42
    关注

    It is the whole scripts of yours? If it is, I think that you don't import the jquery in your frontend scripts

    Please add the jquery in your code, for example :

    <script   src="http://code.jquery.com/jquery-1.12.4.min.js"   integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="   crossorigin="anonymous"></script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用