2014-02-19 42 views
0

我試圖從一個MySQL數據庫中獲取數據。觸發php文件運行

  1. 如何從JavaScript文件觸發一個PHP?

  2. 如何從javascript文件中獲取結果?

+0

google ajax ..... – xdazz

+1

你想使用jQuery嗎?這是一個JavaScript框架。 – Prabhudas

+0

使用Ajax ........ – kcak11

回答

-2

您可以使用腳本爲您的要求:

<script type="text/javascript"> 
function showInformation() 
{ 
if (window.XMLHttpRequest) 
    {// code for IE7+, Firefox, Chrome, Opera, Safari 
    xmlhttp=new XMLHttpRequest(); 
    } 
else 
{// code for IE6, IE5 
    mlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
} 
xmlhttp.onreadystatechange=function() 
{ 
if (xmlhttp.readyState==4 && xmlhttp.status==200) 
{ 
    console.log(xmlhttp.responseText); 
    //this is the result you can get here. 
} 
} 
xmlhttp.open("GET","xxx.php",true); 
//xxx.php is the php file you want to fetch data from 
    xmlhttp.send(); 
} 
</script> 

感謝

這裏是jQuery的腳本來完成相同的操作:

function getInformation(){ 
$.post('xxx.php',{'param':'..value..'},function(response){ 
    console.log(response); 
}); 
} 

注意:在此之前包括jquery.js文件在你的腳本中。

謝謝