2011-04-01 186 views
0
 function viewDetail(pid) 
     { 
       $.post("product.php", { data: pid}); 

       <?php 
       $data = $_POST['data']; 
       retrieve_product_detail($data); 
      ?> 
     } 

這個方法我試過了,但是「PID」的價值是不會功能retrieve_product_detail($data)請幫助我,我如此堅持soooooooooooon通過AJAX變量到PHP

+2

的http://計算器。 com/search?q = pass + javascript + variable + to + php – deceze 2011-04-01 09:30:25

+0

是JS函數中的一個javascript文件嗎? – JohnP 2011-04-01 09:41:19

+0

嘗試調試'$ _POST'來查看它真正包含的內容。 – Capsule 2011-04-01 09:45:03

回答

0
var url = "myurl/myurl.php"; 
var params = "param1=sth&param2=sth"; 
http.open("POST", url, true); 

//header information along with the request 
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
http.setRequestHeader("Content-length", params.length); 
http.setRequestHeader("Connection", "close"); 

http.onreadystatechange = function() {//Call a function when the state changes. 
    if(http.readyState == 4 && http.status == 200) { 
     alert(http.responseText); 
       //or do whatever you want to with the response 
    } 
} 
http.send(params); 
+0

我想他會問jQuery。 – 2011-04-01 09:41:51