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.)