For getting content from another page you only need 3 functions

  • 1 custom function you can call in your code
  • 1 for fetching the results from an external php file
  • 1 for placing the fetched values in you original code

javascript

JavaScript:
  1. function showDetails(){
  2.     xmlHttp=GetXmlHttpObject()
  3.     if (xmlHttp==null){
  4.         alert ("Browser does not support HTTP Request")
  5.         return
  6.     }
  7.     var url="javascript/result/auto.php"
  8.     url=url+"?q=te"
  9.     xmlHttp.onreadystatechange=stateChanged
  10.     xmlHttp.open("GET",url,true)
  11.     xmlHttp.send(null)
  12. }

JavaScript:
  1. function GetXmlHttpObject(handler){
  2.     var objXMLHttp=null
  3.     if (window.XMLHttpRequest){
  4.         objXMLHttp=new XMLHttpRequest()
  5.     }else if (window.ActiveXObject){
  6.         objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
  7.         }
  8.     return objXMLHttp
  9.     }

JavaScript:
  1. functionstateChanged(){
  2.     if (xmlHttp.readyState==4){
  3.         if(xmlHttp.status == 200){
  4.             document.getElementById("booja").innerHTML=xmlHttp.responseText
  5.         }else{
  6.             alert("Problem with request!");
  7.         }
  8.     }
  9. }

html

HTML:
  1. Click<span style="cursor: pointer; color: green" onclick="showDetails()">this</span> to fill the div

The output of this php page "javascript/result/auto.php" will be shown in the "booja" div.

Popularity: 8% [?]