Jump to content

jQuery auto complete producing results bug


Q695
Go to solution Solved by requinix,

Recommended Posts

I'm struggling to produce results to the screen from the following code:

 

HTML:

<script src="http://code.jquery.com/jquery-2.1.4.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<script src="../scripts/autocomplete.js"></script>

<div>
    <input type='text' class='search_input' name='search' id='search' placeholder='search' autofocus onkeypress='search_func("http://webfarm.io/subs/homefront/list_articles.php" , "search_output")'>

    <div id='search_output' class='search_output'></div>
</div>

Javascript:
 

function search_func( href , target){
        var search = $("#search").val();
        search = $.trim(search);

        if(search){
            $.ajax({
                method: "POST",
                url: href ,
                data: { search: search }
            })
                .done(function( msg ) {
                    target.innerHTML = msg; // as above, data holds the result of the request, so all the data returned from your results.php file are in this param but please see below;
                    console.log(msg);
                });
        } else {
            target.innerHTML = '';
        }
}

What am I doing wrong?

Why won't it produce the desired results?

Sorry if I'm looking like a help vamp, but I'm not trying to be.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.