2015-10-20 74 views
0

我可以訪問url「http://localhost:8080/test.php?dbname=zhenhuang」,但下面的代碼不起作用。我想知道如何在javascript中調用php文件。如何遠程調用php文件?

var http=new XMLHttpRequest(); 
    http.onreadystatechange=function(){ 
     console.log(http.readyState);enter code here 
     if(http.readyState === 4){ 
      /*code*/ 
     } 
    }; 
    http.open("GET","http://localhost:8080/test.php?dbname=zhenhuang",true); 
    http.send(null); 
<pre> 

回答

0

如果您想獲得該頁面的內容,你可以:

$result = file_get_contents("http://localhost:8080/test.php?dbname=zhenhuang"); 

更多here

我希望它能幫助! :)