I currently check if an input/textarea/checkbox/select changes and if so then I want to initiate my function to search the database and update the 'results' div. Now this is what I have so far..
It works on change no problem, the only issue is now when I change a form item, it detects it but the new values are not passed to the .php file. Suggestions?
Note: I tried to use the $(this).serialize(); but it didn't work for me. I simply want to pass ALL of the specified form variables to the PHP file.
$(document).ready(function() {
$("select,:checkbox").change(function(){ inits(); });
$("input,textarea").keystop(function(){ inits(); });
a = "GET";
b = "#recipeSearch";
c = $(b).attr('action') + '?r';
f = "#searchResults";
function inits(){
var values = {
'term' : $("input#searchterm").val(),
'photos' : $(b + " #requirephotos").val(),
'prep' : $(b + " #preptime").val(),
'cook' : $(b + " #cooktime").val()
}
console.log('Search Init');
$.ajax({
url: c,
cache: false,
dataType: 'json',
data: values, // $(b).serialize(); // this still didn't work
success: function(response) {
//decoded = JSON.stringify(response);
if (response) {
$(f).html(response);
}
//$.each(r.items, function(i,data){} //usage later on
},
error: function(e, jqxhr, settings, exception) {
console.log('Error: ' + e.toString() + ' - ' + jqxhr);
}
});
}
});
Any and all suggestions are appreciated. I don't have a jsfiddle for you since it uses another script for keystop.
Example JSON
{
"items": [
"item 1",
"item 2",
"item 3",
"item 4",
"item 5"
]
}