如何发布此数组并在 php 中打印
How to post this array and print in php?
如何将这个数组发送回服务器,以便我可以在PHP中处理它?
<script>
var myJSONObject = {
"onw": [
{"name": "nilesh", "age": "31", "sal": "4000"},
{"name1": "nitin", "age": "11", "sal": "14000"}]
};
document.write(myJSONObject.join());
</script>
您可以使用序列化方法。 即序列化JavaScript变量并将其传递给PHP,在PHP文件中您可以反序列化相同的变量。
序列化:在jQuery中序列化为JSON
参考: http://api.jquery.com/serializeArray/
永远不要使用 document.write 因为它已经过时了,将元素添加到 DOM 的首选方法是使用 appendChild
用于追加的示例代码:
var textNode = document.createTextNode("some text"); // creates new text node
textNode.appendChild(document.body); // adds to the end of the body
对于使用 jquery 将数据发布到 php:
在将其发送到服务器之前,您需要使用 JSON.stringify 将其格式化为字符串
var formattedData = JSON.stringify(myJSONObject )
$.ajax({ type: "POST", url: "server.php", data: formattedData , dataType: 'json', success: function () { alert("Data posted to php and processed succesfully"); } });
var json_text = JSON.stringify(myJSONObject, null, 2);
警报(json_text);
相关文章:
- 如何用javascript打印php数组
- 表单中的提交按钮在 PHP 打印中不起作用
- php:打印javascript/jquery dom就绪
- 如何使用PHP打印JavaScript
- 使用javascript获取浏览器历史记录,并通过php打印
- php/js 工具或函数,以防止从 php 打印到 javascript 时出现“意外非法”
- PHP 打印 $_POST['something'],无需刷新
- 如何使用PHP打印功能打印图像
- php打印上的脚本高亮效果
- 如何用PHP打印页面以使用与window.print()相同的打印机进行打印
- 用jQuery和php打印成html
- PHP打印PDF文件到指定的网络打印机而不打开对话框
- 如何从PHP打印按钮调用JavaScript函数
- 如何使用php打印出网页的某些部分
- 使用Javascript/AJAX和PHP打印出值
- 使用PHP打印函数时,JQuery / JavaScript中的引号
- 用PHP打印几个不同的页面
- 命令在没有提示的情况下用php打印页面
- 在php打印函数中编写有参数的onclick方法
- 如何使用jquery或php打印特定的日期's月