我有一个特定的数组,php需要访问并写入文件。我也希望能够调用php来获取数组信息。我使用JSON.strigify将数组存储在一个字符串中,但我无法弄清楚如何使用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;
?>
我用echo来看看我是否得到任何输出,但我不是。它可能是一个非常简单的修复,也许我错过了一个标题或者告诉我的html文档读取main.php?任何帮助将不胜感激!
答案 0 :(得分:2)
答案 1 :(得分:1)
您可以添加hiddenField并将字符串设置为隐藏字段。 php代码将从隐藏字段中读取值。