I'm new to front-end programming and using multiple new (to me) technologies on a project (boostrap, grails, jquery). So, the following issue may be a no-brainer to experienced font-end developers, so please humor me.
The Issue: I cannot figure out why for the life of me, the button.click function in jquery scrip is not triggering. Neither the alert is triggered, nor the actual ajax call to the URL. The body tag of the .gsp file, including the script, is below. Help!
<body>
<div id="top"/>
<div class="container-fluid">
<div class="row">
<div class="col-xs-1"></div>
<div class="col-xs-10">
<div class="input-group">
<input id="searchQuery" type="text" class="form-control" placeholder="${message(code: 'search.enterquery', default: 'Enter query')}" >
<span class="input-group-btn">
<button id="searchButton" class="btn btn-default" type="button"><g:message code="search.search" /></button>
</span>
</div>
</div>
<div class="col-xs-1"></div>
</div>
<div class="row">
<div id="searchResults">
Results will appear here
</div>
</div>
</div>
<script type="text/javascript" language="javascript">
$(document).ready(function(){
$("#searchButton").click(function() {
alert("button was clicked");
$.ajax({
type: "POST",
url: "${g.createLink(controller:'library',action:'search')}",
dataType: 'html',
data: { query: $("#searchQuery").val()},
success:function(result){
$("#searchResults").html(result);
}
error:function() {
$('#searchResults').text('An error occurred');
}
complete:function() {
}
});
});
});
</script>
</body>