Jquery .post() Return Html Into Table
I have a form with two input boxes. Song and Artist. When the search button is pressed, it uses the JQuery function of .post() to post the data to a PHP page and return results b
Solution 1:
Try this...
<script>
$(function() {
$("#submitSearch").bind("click", function(e) {
e.preventDefault();
var songTitle = $("#song").val();
var artistName = $("#artist").val();
$.post("getSearchResults.php", {
artist: artistName,
song: songTitle
},
function( data, status ) {
$("#searchResults tbody").last().append( data );
});
});
});
</script>
I added an event parameter to the click function, and e.preventDefault()
. this stops the submit actually taking place, which is reloading your page. Also, depending on which version of jQuery you are using you may want to use on()
instead of bind()
. (It's exactly the same syntax as above.)
Post a Comment for "Jquery .post() Return Html Into Table"