Support the ongoing development of Laravel.io →
posted 5 years ago
Last updated 1 year ago.
0

Can you show your ajax code?

0

Hey, yes it is:

$("#searchInput").on('keyup', function(e){
        var query = $(this).val();
        if(query.length > 0) {
            $(".searchDropdown").empty();
            var isProcessing = false;
            if(!isProcessing) {
                $.ajax({
                    method: 'POST',
                    url: 'doSearch',
                    data: {
                        query: query
                    },
                    beforeSend: function () {
                        isProcessing = true;
                    },
                    success: function (data) {
                        $(".searchDropdown").empty();
                        if (data.status === "success") {
                            $.each(data.spot_list, function (i, v) {
                                $(".searchDropdown").prepend("<li class=\"dropdown-item\" style=\"cursor: pointer;\"><a class=\"blackColor\" href=\"asd\"><b>#" + v.id + "</b> " + v.text + "</a></li>");
                            });
                            if (data.othersResults == true) {
                                $(".searchDropdown").append("<li class=\"dropdown-item\" style=\"cursor: pointer;\"><a class=\"blackColor\" href=\"asd\"><b>Altri risultati...</b></a></li>");
                            }
                            $(".searchDropdown").show();
                            isProcessing = false;
                        }
                    }
                });
            }
        } else {
            $(".searchDropdown").hide();
        }
        return false;
    });

But this code in my home works well.

This is the home route:

Route::get('home', function(){
stuff to check if userlogged
});
Last updated 5 years ago.
0

Problem is in your AJAX method . Your route accept GET request ,but you are trying to POST .

 $.ajax({
   method: 'POST',  // change to GET
 })
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.