javascript - How display Wikipedia search? -


i have started programming in javascript , have create own wikipedia page using wikimedia api can't understand when search clicked how pull data text box , display result.

<!doctype html> <html>  <body>  <h1>wikipedia</h1> <div id="search1" /> <input type="text" name="search" /></b> <button id="s1">search</button> </div> <p id="display"></p>    <script> var xmlhttp = new xmlhttprequest(); var url = "https://community-wikipedia.p.mashape.com/api.php" ;  xmlhttp.onreadystatechange=function() {     if (xmlhttp.readystate == 4 && xmlhttp.status == 200) {         myfunction(xmlhttp.responsetext);     } } xmlhttp.open("get", url, true); var key = "ocdv3mjlj1mshtyixwbvzbqrkty9p1xjniajsn1vscetyvlwk3"; req.setrequestheader("x-mashape-key", key); xmlhttp.send();  function function(response) {  var = json.parse(response);  var i;  text = "";  for(i = 0; < a.length; i++) {      text += a[i]+ "<br>";  }  document.getelementbyid("search1").addeventlistener("click",displaysearch);  function displaysearch(){  //display search items here  }   }  </script>  </body> </html> 

you use iframe in html setups after click search button, or can use jquery ajax call that's sends call request wikipedia page accessing , if successful returns appropriate data.

 $.ajax({     url: '/path/to/file',     type: 'default (other values: post)',     datatype: 'default: intelligent guess (other values: xml, json, script, or html)',     data: {param1: 'value1'}, }) .done(function() {     console.log("success"); }) .fail(function() {     console.log("error"); }) .always(function() {     console.log("complete"); }); 

jquery better option of two. (in opinion)

an alternative iframes (in javascript):

var ifrm = document.createelement('iframe'); ifrm.setattribute('id', 'ifrm'); ifrm.setattribute('src', 'demo.html'); //url can go here document.body.appendchild(ifrm); //places iframe @ end of page 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -