Search
 
SCRIPT & CODE EXAMPLE
 

PHP

ajax search request

function filterSearch() {
	$('.searchResult').html('<div id="loading">Loading .....</div>');
	var action = 'fetch_data';
	var minPrice = $('#minPrice').val();
	var maxPrice = $('#maxPrice').val();
	var brand = getFilterData('brand');
	var ram = getFilterData('ram');
	var storage = getFilterData('storage');
	$.ajax({
		url:"action.php",
		method:"POST",
		dataType: "json",		
		data:{action:action, minPrice:	minPrice, maxPrice:maxPrice, 
brand:brand, ram:ram, storage:storage},
		success:function(data){
			$('.searchResult').html(data.html);
		}
	});
}
Comment

Search with ajax

// search option with ajax 	
// url 
  Route::post('/serach', 'value')->name('search.product');
// controller logic
public function value(Request $request)
    {
        $search = $request->searchValue;
        if ($search) {
            $product = Product::select('id', 'title', 'slug')
                ->where('title', 'Like', '%' . $search . '%')
                ->get();
                return json_encode($product);
        }else{
            return response('No Product', 404);
        }
    }
<script>
    let search = $('.search')
    let search1 = $('.search1 ul')
    let myurl = `{{ route('search.product') }}`
    search.on('keyup', function() {
        let value = $(this).val()

        setTimeout(() => {

            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': "{{ csrf_token() }}",
                },
                url: myurl,
                type: 'post',
                dataType: 'json',
                data: {
                    searchValue: value,
                },
                success: function(response) {
                    let results = response
                    // console.log(results)
                    let lists = []
                    results.map(result =>{
                        list = `<li><a href="/view/product/${result.id}">${result.title}</a></li>`;
                        lists.push(list)
                    })
                    search1.html(''),
                    search1.html(lists)
                },

                error: function(){
                    search1.html(" ")
                }
            })
        }, 500);
    })
</script>
Comment

PREVIOUS NEXT
Code Example
Php :: laravel optional params 
Php :: php get filename 
Php :: yii2 gridview action change urls 
Php :: array_merge 
Php :: laravel max length format 
Php :: php trim 
Php :: laravel eloquent duplicate record 
Php :: two column date compare in php 
Php :: laravel wrong timestamp 
Php :: php get last index of array 
Php :: php remove value from array 
Php :: file upload using ajax in laravel 
Php :: how to create resource controller in laravel 
Php :: link to internal pages in wp php 
Php :: last insert id mysqli 
Php :: Get All dates of a month with laravel carbon 
Php :: wordpress add shortcode with parameters 
Php :: remove square brackets from string php 
Php :: laravel pdf export 
Php :: Calling itself a static function in php 
Php :: drupal 7 db_query example 
Php :: php check jwt token expired 
Php :: php value in array 
Php :: wordpress post add input field 
Php :: laravel logout after password change 
Php :: laravel CORS config `allowed_origins` should be an array 
Php :: carbon get month from date 
Php :: how to check if a user is logged in in a non middleware controller in laravel 
Php :: php mysqli insert name adress 
Php :: laravel looping checking if last record has reached 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =