When I perform a search, the results are returned and shortly after, the page redirects to a servlet displaying raw JSON data. It's a bit confusing for me.
This JSP form submission:
<form class="col-lg-12" action="./urllinks" method="GET" id="searchform">
<div class="input-group"
style="width: 340px; text-align: center; margin: 0 auto;">
<input class="form-control input-lg" title="Make a wish !."
placeholder="Go on and search ! Don't be shy :p" type="text" id="box"
name="query"> <span class="input-group-btn"><button
class="btn btn-lg btn-primary" id="searchresult" type="submit">Search</button></span>
</div>
</form>
This is the Servlet GET method:
String word = request.getParameter("query");
List<Page> results = DynamoDbMethods.search(word);
String reply = new Gson().toJson(results);
response.setContentType("text/json");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write(reply);
This is the JavaScript AJAX:
$('#searchform').submit(function(){
var query = $("#box").val();
// alert(query);
$.ajax({
target:"#map",
dataType: "json",
type: 'GET',
data:{query: query},
url: 'http://localhost:8080/path/urllinks',
success: function(response) {
successCallback(response);}
});
});
function successCallback(responseObj){
#This function just prints the data on a table
#e.g
$.each(responseObj, function(index, element){ alert(element.title);}
}
I attempted to remove action="./urllinks" method="GET
but then no data was retrieved.