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条回答 默认 最新

  • George_Fal 2016-07-25 15:59
    关注

    Follow jQuery Ajax Document :

    An alias for method. You should use type if you're using versions of jQuery prior to 1.9.0

    type: 'POST'
    

    But you are using 2.0 so i think this will work :

    method: 'POST'
    

    jQuery Documents

    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?