rodolfo navalon
rodolfo navalon

Reputation: 193

how to get the data from the input box to ajax

I am new to ajax and wondering how can I get the data from input and pass it to ajax so I can use the data to the php box and do I need to specify the this.val of the input??

here my code so far

div class="findfriend">

    <input type="text" id="findtext" name="friendfinder" placeholder="Enter Text to find a friend"/>
    <button id="buttonfriend" class="findfriendbutton"></button>
</div>
<div class="outputfindfriend">
   <ul class="ulfriendfind">
     <li class="lifindfriend"><a class="searchResult" href="#"></a></li>
    </ul>

<script>
    $("#findtext").keydown(function () {
        $.ajax({
            url: 'resultFindFriend.php',
            type: 'post',
            data: { dataFriend: $(this).val },
            success: function (data) {
                $('.outputfindfriend .searchResult').html(data);
            }
        });
    });

</script>

Upvotes: 0

Views: 856

Answers (1)

Jacob Mattison
Jacob Mattison

Reputation: 51062

The first issue that jumps out at me is the line

      data: { dataFriend: $(this).val },

which should be

      data: { dataFriend: $(this).val() },

(i.e. val() is a function, not a property.)

Upvotes: 2

Related Questions