. Hello yall, I'm trying to use ajax to run a search and then have it return links to the search results' pages with a checkbox next to each result so that the user can select orders to print.
I figured out the link part but am not sure how to use each search result to make a checkbox.
I tried working with the "success:" part of the ajax in the JS but couldn't just broke it every time.
Ideally when the ajax is all said and done it will have a link_to("/{$search_table}/{$result->id}/", $result->street_address) link and then a checkbox with an id = "$search_table + '_' + $result" (so for example an id of "order_123TestStreet").
Any pointers or helpers would be greatly appreciated! Thank so much!
JS:
$(document).ready(function(){
$("#search_form").submit(function(e) {
e.preventDefault();
//form_data
var form_data = $('#search_form').serializeArray();
$.ajax({
url: 'search',
type: "POST",
dataType: "html",
data: form_data,
success: function(data){
$("#search_results").html(data);
$("#search_results").addClass('panel callout radius');
},
error: function(xhr, status, error){
console.log(xhr);
console.log(status);
console.log(error);
}
});
});
});
Controller:
public function search(){
$validator = Validator::make(
array(
'search_table' => Input::get('search_table'),
'search_column' => Input::get('search_column'),
'search_input' => Input::get('search_input'),
),
array(
'search_table' => 'required',
'search_column' => 'required',
'search_input' => 'required',
)
);
if($validator->fails()){
exit;
} else {
/*Run Search Query*/
$search_table = Input::get('search_table');
$search_column = Input::get('search_column');
$search_input = Input::get('search_input');
$search_results = DB::table($search_table)->where($search_column, 'LIKE', "%{$search_input}%")->get();
foreach($search_results as $result){
$result_street_address = $result->street_address;
echo link_to("/{$search_table}/{$result->id}/", $result->street_address) . "<br>" . "<br>";
}
}
}