我有一個特定的數組,PHP需要訪問和寫入文件。我也希望能夠調用PHP來獲取數組信息。我使用JSON.strigify將數組存儲在字符串中,但我無法弄清楚如何使用php將其發送到服務器。我很少有PHP的經驗,我想:我有一個變量,我需要發送到PHP被寫入到文件
<script language="javascript">
var COMMENTS_FOR_DISPLAY = new Array('Have fun with this code: Chris');
// Adds a new comment, name pair to the Array feeding textualizer.
function add_comment() {
// Retrieve values and add them to Array.
var new_comment = $('#kwote').val();
var new_name = $('#name').val();
COMMENTS_FOR_DISPLAY.push(new_comment + ': ' + new_name);
// Reset <input> fields.
$('#kwote').val('');
$('#name').val('');
var arrayAsString = JSON.stringify(COMMENTS_FOR_DISPLAY);
}
$(document).ready(function() {
var txt = $('#txtlzr'); // The container in which to render the list
var options = {
duration: 5, // Time (ms) each blurb will remain on screen
rearrangeDuration: 5, // Time a character takes to reach its position
effect: 'random', // Animation effect the characters use to appear
centered: true // Centers the text relative to its container
}
txt.textualizer(COMMENTS_FOR_DISPLAY); // textualize it!
txt.textualizer('start'); // start
});
</script>
在main.php我把:
<?php
$kwoteString = $_GET["arrayAsString"];
echo $kwoteString;
?>
我用回聲看看,如果我得到任何輸出,但我不是。它可能是一個非常簡單的修復,也許我錯過了一個頭文件或告訴我的HTML文檔閱讀main.php?任何幫助,將不勝感激!
你缺少這樣的:http://api.jquery.com/jQuery.ajax/ – 2012-04-17 15:50:12
Ummmm ......這是什麼都與PHP或JSON辦? – 2012-04-17 15:51:08
AJAX是需要經由HTTP請求客戶端和服務器端之間的通信... – gorelative 2012-04-17 15:55:23