weixin_33681778 2016-07-25 15:44 采纳率: 0%
浏览 18

Ajax未执行

I am beginner to ajax world and trying to call contents from php page using $.ajax() function and the code couldn't executed. the html page i used:

<!DOCTYPE html>
<html>
<head>
    <title>AJAX</title>    
</head>
<body>

<div >    
    <input type="text" name="search" id="search">       
    <br>
    <br>
    <h2 id="result"></h2>
</div>    
<script   src="https://code.jquery.com/jquery-2.2.4.min.js"   integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="   crossorigin="anonymous"></script>
<script src="js/script.js"></script>
</body>
</html>

the JQuery code i used in the script.js:

$(document).ready(function() {

    $('#search').keyup(function () {
        var search = $('#search').val();

        $.ajax({

            url:'search.php',
            //the page to which the request will go to

            data:{search: search},

            type: 'POST',
            success:function(data) {
                if(!data.error){
                    $('#result').html(data);//the h2 we want to echo it uing the ajax
                }
            }

        });

    });

});

the search.php page contain:

$search = $_POST['search'];
echo $search;

the code not executed. What should I do.

  • 写回答

2条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 macOS使用IDEA 2022.2.4打包JDK6项目报错
      • ¥20 OpenCV-Python简单轮廓寻找
      • ¥20 使用matlab进行含参数的最优化求解及数值模拟
      • ¥20 MATLAB找出一维变量中的局部极大值和局部极小值,并进行运算
      • ¥15 有Chang求三维杆单元几何非线性分析matlab代码
      • ¥50 使用unity easyar录屏功能。录屏视频整体色调很暗
      • ¥50 pyinstaller 打包问题
      • ¥15 无法使用cnssc调取网页数据
      • ¥15 Pycharm安装en_core_web_sm失败出现Could not find a version that satisfies the requirement spacy报错
      • ¥15 Python社区划分