I am attempting to implement a get request via $.ajax
upon the user submitting a form.
I am not sure if what I am doing is the most efficient method (binding a click to the form button) so if there is a more efficient way (or standard way), please suggest it!
My result is that the content div is filled properly in FF/Chrome, but IE it is not. IE seems to be submitting the form and reloading the page entirely.
In addition, I really do think I need to "submit" the form, because I want to take advantage of jQuery validate();
which does not work with the below implementation (even in FF/Chrome).
Javascript:
$(document).ready(function(){
$("#theForm").submit(function(){
// build our data to send in our request
var mydata = {method: "search", color: $('#color').val()};
$.ajax({
url: 'foo.php',
data: mydata,
type: 'get',
dataType: 'json',
success: function(data){
$("#content").html(data);
}
error: function(e){
console.log(e.message);
}
});
return false;
});
});
HTML :
<form id="search">
<input type="submit" />
</form>
<div id="content"></div>