Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

zione8036's avatar

the search button is not working after I deploy

The search feature is not working after I deployed my website but it is working on my localhost. In the first picture, I am able to search for anything on my localhost and able to query any data I want. But after I deploy it online, the search feature is not working.

IMAGE[1] https://i.stack.imgur.com/jjyED.jpg

IMAGE[2] https://i.stack.imgur.com/qRo9A.jpg

    @if($products -> isEmpty())
<h3 class="text-center text-danger">Product not found</h3>
@else

<div class="container mt-5">

    <div class="row d-flex justify-content-center ">

        <div class="col-md-6">

            <div class="card">
                @foreach($products as $item)
                <a href="{{ url('product/details/'.$item->id.'/'.$item->product_slug_en ) }}">
                    <div class="list border-bottom">
                        <img src="{{asset($item->product_thambnail)}}" style="padding-right: 10px; width: 120px; height: 60px; border-right: 2px solid #eee;">
                        <div class="d-flex flex-column ml-3" style="margin-left: 10px;">
                            <span>{{$item->product_name_en}}</span>
                            <small style="margin-left: 5px;">₱{{$item->selling_price}}</small>
                        </div>
                    </div>
                </a>
                @endforeach
            </div>

        </div>

    </div>

</div>
@endif 


   jQuery("[data-toggle='tooltip']").tooltip(); 
const site_url = "http://test.wt-g.shop/";
$("body").on("keyup", "#search", function(e){
    let text = $("#search").val();
    if (text.length>0){
     $.ajax({
         data : {search: text}, 
         url : site_url + "search-product",
         method : 'post',
         beforSend: function(request){
            return request.setRequestHeader('X-CSRF-token',("meta[name='csrf-token']"))
         },
         success:function(result){
             $("#searchProducts").html(result)
         }
     });
    }if(text.lengh<1){
        $("#searchProducts").html("");
    }
});  

public function SearchProduct(Request $request)
    {
        $request->validate(["search" => "required"]);
        $item = $request->search;

        $products = Product::where('product_tags_en', 'LIKE', "%$item%")
            ->orwhere('product_color_en', 'LIKE', "%$item%")
            ->orwhere('product_name_en', 'LIKE', "%$item%")
            ->select('product_name_en', 'product_thambnail', 'selling_price', 'id', 'product_slug_en')
            ->get();
        return view('frontend.product.search_product', compact('products'));
    }
}
0 likes
4 replies
Sergiu17's avatar

what do you get in Response tab in dev tools?

Sergiu17's avatar
Sergiu17
Best Answer
Level 60

@zione8036 looks like your AJAX request goes to http://127.0.0.1:8000/search-product which is incorrect, make sure to change your config files / references. If the js code is inside blade in the same app with Laravel, then

url could be simple: url : "/search-product",

instead of: url : site_url + "search-product",

Snapey's avatar

you don't want to be hard coding the url in your javascript. As @sergiu17 says, just make it relative to the same host

Please or to participate in this conversation.