skip to Main Content

I am building a filter function in ajax and php (I am new to ajax). I have an html input like this:

<form>
    <input type="text" placeholder="Search" onkeyup="getListSearch(this.value)" name="search_filter">
</form>

The current function getListSearch looks like this

function getListSearch(filter) {    
    $.ajax({
        method  : "POST",
        url     : "www.example.com/includes/content.php",
        data    : {
            search_filter: filter
        },
        success : function(result) {
            $("#list_content").html(result);
        }
    });
}

This works but loads the whole result, I only want to show the div with class .list_content from content.php.
I tried the below codes

$("#list_content").html($(result).find('.list_content'));
// Tried below also
$("#list_content").load(result + " .list_content");

But no success.
Any help would be appreciated.

2

Answers


  1. Chosen as BEST ANSWER

    Thanks for the response, this worked for me:

            function getListSearch(filter) {
    
            $('#list_content').load('www.example.com/includes/content.php #list_content', {
                search_filter: filter //Post for content.php
            });
    
        }
    

  2. function getListSearch(filter) {    
        $.ajax({
            method  : "POST",
            url     : "www.example.com/includes/content.php",
            data    : {
                search_filter: filter
            },
            success : function(result) {
                var dom_nodes = $($.parseHTML(result));
                $("#list_content").html(dom_nodes.find('.list_content').html());
            }
        });
    }
    
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search