L
L
Lulzsec2018-01-29 11:36:59
PHP
Lulzsec, 2018-01-29 11:36:59

Search form + request by JS + json + AJAX?

Hello.

There are:
1) my site has a simple API, json is issued upon request.
2) the site has a search form for something

I want to do the following:
1) When entering each character in the form, a request is sent to my site (let it be site.ru/api/search?q=123)
2) Just below the form, the found one is loaded content from the 1st point

Are there ready-made solutions or libraries? Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ramm, 2018-01-29
@Lulzsec

Use the onChange event

$(document).ready(function(){
    $(".matchedit").on('input', function postinput(){
        var matchvalue = $(this).val(); // this.value
        $.ajax({ 
            url: 'matchedit-data.php',
            data: { matchvalue: matchvalue },
            type: 'post'
        }).done(function(responseData) {
            // подгружаете контент (responseData) в HTML
        }).fail(function() {
            console.log('Failed');
        });
    });
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question