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