Problem
I'm trying to query a rest API in javascript and use jQuery to parse and insert the results into my webpage. When the query is made I believe it submits the search form and re-renders the page thus removing all of the elements I just queried and inserted.
Is there away to get a JSON object from a rest api and not re-render the webpage?
Here's what I'm using to make my requests:
function get_data(){
var url = "www.rest_api/search_term&apikey=My_Key"
var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", url, false );
xmlHttp.send( null );
return xmlHttp.responseText;
}
The search term comes from a simple input form, and is submitted when the submit button is clicked. My goal is to keep this webpage to a single page and avoid a results page.
What I've tried
Get JSON data from external URL and display it in a div as plain text
http://api.jquery.com/jQuery.getJSON/
Request URL example: