我只是想在這裏檢查一下 - 你必須在PHP中通過(jQuery)XHR來檢索它們的值嗎?如何將值從PHP發送到jQuery:echo還是返回?
例如
PHP:
public function processRequest() {
//intercept AJAX requests
if (!empty($_GET)) {
if (isset($_GET['xhr'])) {
if ($_GET['xhr'] == true) {
//process AJAX
//call relevant method
echo json_encode(array('key' => 'value'));
return;
}
}
}
//else proceed with regular output
$this->render();
}
的jQuery:
function doAjax(){
$.ajax({
url: "index.php?xhr=true",
cache: false,
dataType: 'json',
success: function(data){
console.log(data);
}
});
}
這將記錄在螢火蟲控制檯JSON對象用適當的值。 如果我試着返回的價值而不是回聲,我得到nada。
啊,我沒有意識到,jQuery補充說,我在D.Walsh的博客上看到,它不是一個可靠的索引 – sunwukung 2010-08-12 11:38:29