How to pass multiple values through Ajax in laravel?

Posted 7 months ago by AbdulBazith

I am having form view.blade which shows the data of all sales_details (my table) in tabular format.

I am having three text boxes in my view.blade which I am using for search option.

This is my view.blade (just I copied the search box code only)


 <thead>

            <th > {{ Form::text('search_name',null,array('class'=>'form-control','id'=>'search_name','name'=>'search_name')) }}</th>
            <th> {{ Form::text('search_area',null,array('class'=>'form-control','id'=>'search_area','name'=>'search_area')) }}</th>
            <th> {{ Form::text('search_booth',null,array('class'=>'form-control','id'=>'search_booth','name'=>'search_booth')) }}</th>

</thead>

This is my JavaScript


<javascript>

$('#search_name').on('keyup',function(){

$value1=$('#search_name').val();
$value2=$('#search_area').val();
$value3=$('#search_booth').val();
    
$.ajax({

type : 'get',

url : '{{URL::to('search_name')}}',

data:{'search_name':$value1
    'search_name':$value2
'search_name':$value3

},

success:function(data){

 $('tbody').html(data);

}

});

})

</script>

This is my controller


public function search_name( Request $request )

{
                    $output="";

                    $sales=Sales_details::where('customer_name','LIKE','%'.$request->search_name.'%')                  
                    ->orWhere('customer_area','LIKE','%'.$request->search_name.'%')
                    ->orWhere('customer_booth','LIKE','%'.$request->search_name.'%')
                   
                    ->paginate(10);
    
    if($sales)

    { 
        //Need to return the output to the ajax
    }
    else
    {
        // Need to perform some thing
    }
}

My doubt is I am writing the JavaScript in onkeyup event for the textboxes. I have entered some text in first text box and some text in second textbox an when I enter content in third textbox the ajax should fetch all the three content from three text boxes and it should pass to the function search() in the controller. [Will be better if any of the textbox is gets the onkeyup event the same ajax function must be called how?]

Then another doubt is after passing the three content those three must be used to where conditions in the function.

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.