Your form's select
doesn't have a search_column
name
attribute, which is the name that Laravel uses to identify the field when using Input::get()
.
Use something like this :
<select id="whatever" name="search_column">
As for the Javascript, try this code :
$('#search_form').click(runSearch);
var runSearch = function(e){
e.preventDefault();
$('form#search_form').submit(function(){
$.ajax({
url: '/search',
type: 'post',
cache: false,
data: $('#search_form').serialize(),
success: function(data){
console.log("Success!");
$('#search_results_div').html(data);
},
error: function(xhr, textStatus, thrownError){
alert('Somethin went wrong');
}
});
});
};
First you don't need to post it in JSON format, the default URL-encoded format is more than enough and works just fine with Laravel's Input::get("variable")
(I'm not even sure if it actually accepts JSON at all).
Next, the actual data wasn't present in your code, so your request was empty and obviously Laravel wasn't happy because all three input variables were empty and the DB query was failing (by the way, you should use validation to check if the input is present and if not return a nice & clean error message instead of failing completely).
The data
variable is set to serialize()
your form, it "converts" your form into an URL-encoded query string.
Finally the success function sets the HTML content of search_results_div
to the data returned by Laravel (you should return a view there, currently you just return JSON).
I suggest you also look at some of these questions, they may contain code that you can fix using the answers provided and then reuse :