2012-10-12 72 views
0

我试图通过对当前页面发出的请求发送值“hi”给php变量“text”。对同一页面使用jquery post请求

jQuery的

$.post("", "hi"); 

PHP

if (isset($_POST['POST'])) { 
    $text = $_POST['POST']; 
} 
+2

哟耶听说你喜欢的职位...所以我把POST在you'r $ _ POST –

回答

2

个JS:

$.post("", {data:"hi"},function(data){ 

}); 

PHP:

if (isset($_POST['data'])) { 
    $text = $_POST['data']; 
} 
0

做这样的:

$.post("", "text=hi");// You have to pass "key=value" pairs 

在PHP:

if (isset($_POST['text'])) { 
    $text = $_POST['text']; //$text will contain 'hi' 
}