jquery - JavaScript get JSON from rest API without re-rendering the page -
problem
i'm trying query rest api in javascript , use jquery parse , insert results webpage. when query made believe submits search form , re-renders page removing of elements queried , inserted.
is there away json object rest api , not re-render webpage?
here's i'm using make 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 simple input form, , submitted when submit button clicked. goal keep webpage single page , avoid results page.
what i've tried
get json data external url , display in div plain text
http://api.jquery.com/jquery.getjson/
request url example:
remember when calling jsonp apis, have add additional parameter url : callback=?
here's simple fiddle example: http://jsfiddle.net/8dxxn/
Comments
Post a Comment