简体   繁体   中英

Javascript script (ajax) not working (php+ajax for live search)

I tried to make live search with php and ajax but this function is not working at not it's not entering the script.. I don't know why. The PHP code is working.

<form autocomplete="off">
    <input type="search" id="search" name="search" placeholder="Search..." />
</form>

<br>

<div id="search_result"></div>

<script>
$(document).ready(function(){
    $("#search").keyup(function(){
        $("search_result").show();
        var txt = $(this).val();
        $.ajax({
            type="GET",
            url:"fetch.php",
            data:"q=" + txt,
            success:function(data)
            {
                $("#search_result").html(data);
            }
        });
    });
});
</script>
$("search_result").show();

should be

$("#search_result").show();

and as mentioned

type="GET",

should be

type: "GET",

What is the php code returning? And what are the console errors?

type="GET"type: "GET"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM