将ajax变量传递给php

时间:2011-04-01 09:28:31

标签: jquery

        function viewDetail(pid)
        {
               $.post("product.php", { data: pid});

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

我也尝试过这种方法,但是'pid'的值不会转到函数retrieve_product_detail($data)请帮助我,我太困了所以太懒了

1 个答案:

答案 0 :(得分: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);