朋友,我不知道是否有可能或沒有,但要做到像下面所提到的,如果可能的話給我最好的解決辦法..jQuery的AJAX JSON數組到PHP變量
的index.php
<?php
mysql_connect('localhost', 'root', '') or die (mysql_error());
mysql_select_db('mydb') or die (mysql_error());
?>
<html>
<head>
<script type="text/javascript" src="jquery-1.8.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('input[type="button"]').click(function(){
$.ajax({
url : 'ajax.php',
success : function(data){
alert(data);
}
});
});
});
</script>
</head>
<body>
<input type="button" name="button" value="Submit">
<?php print_r($_REQUEST['data'])?>
</body>
</html>
ajax.php
<?php
mysql_connect('localhost', 'root', '') or die (mysql_error());
mysql_select_db('mydb') or die (mysql_error());
$query = mysql_query('select * from user');
$count = count($query);
while($row = mysql_fetch_array($query)) {
$data['name'][] = $row['name'];
}
print json_encode($data);
?>
當我點擊提交阿賈克斯將調用,並將從JSON編碼字符串得到迴應如下
{"name":["Nakul Kabra","Bridget Louise","Jayesh Joshi","Jignesh Chaudhary","Jitendra Vihol","Spec Develop","Harshad Sadclown","Andy Estep","Rohan"]}
現在我想將這個ajax響應存儲在PHP變量中並顯示它。 如何解決這個問題,任何人都可以幫助我.. ??
謝謝,提前! 您的問候。
當你收到你將在客戶端,你不能運行PHP的響應。您在客戶端使用JavaScript。 –
一旦你設置了它,你想在哪裏再次使用該變量? –
是的,你是對的,但仍然有任何方式或任何我們如何能夠將該json數組存儲在php數組中..你有任何想法或邏輯..嗎? –