2012-04-17 44 views
1

我有一个特定的数组,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?任何帮助,将不胜感激!

+2

你缺少这样的:http://api.jquery.com/jQuery.ajax/ – 2012-04-17 15:50:12

+0

Ummmm ......这是什么都与PHP或JSON办? – 2012-04-17 15:51:08

+0

AJAX是需要经由HTTP请求客户端和服务器端之间的通信... – gorelative 2012-04-17 15:55:23

回答

1

你可以添加一个hiddenField并设置该字符串的隐藏字段。 php代码将从隐藏字段中读取值。

相关问题