2012-09-12 25 views
0

當URL中有一些$ _GET信息時,例如:index.php?WhatIWant = 1。我們如何使用ajax恢復該值?

我想它使用$ _GET [ 'WhatIwant']在PHP的一部分,這樣的恢復:

PHP:

<?php 

echo $_GET['WhatIwant']; 

?> 

的jQuery:

$.post('functions/test.php',function(test) 
{ 
    $('.value').text(test); 
}); 

,但我一直得到「未定義的索引:WhatIwant」,我認爲這是有道理的。但是如何恢復呢?

回答

0

它返回undefined的原因是因爲你發佈到函數/ test.php,它不會有$ _GET var set。

如果您wan't到能夠訪問它在JavaScript我建議像下面這樣:

var randomGet = <?php echo(isset($_GET['random']) ? '"' .$_GET['random']. '"' : ''); ?>; 
alert(randomGet);