GetJSON is triggered by a button inside the form
I'm having trouble figuring out why I have to put a button that fires the getJSON method outside of the form for the request to work.
If a button is placed on a form, the getJSON method returns no results.
The base code uses an XHR request when the Submit button is clicked based on the selected value. I reproduced this question here: http://jsfiddle.net/z6caj/
Many thanks,
a source to share
Clicking the button will submit the form in the normal way (when placed inside the form). return false
at the end of the click handler and it should work as expected. Alternatively, disallow the submission by submitting a form handler return false
:
$("form").submit(function() {
return false;
});
a source to share
Because this is a submit button and you are not doing anything to prevent the default action.
So the JS starts up (setting the Ajax request) and then the form is submitted (leaving the page and discarding the request).
See http://docs.jquery.com/Tutorials:How_jQuery_Works (section starting with "For clicks and most other events")
a source to share