javascript - 从json数据中获取php页面中的数据
问题描述
我有一个 HTML 表单,我将其转换为 JSON 并将其传递到另一个页面save.php
。问题是我看不到save.php
页面上的数据。
我的 HTML 表单代码:
<form id="my-profile" action="save.php">
<div id="accordion" style="width:80%; margin:0 auto;background:">
<div class="s_panel">
<div>
<h3 style="width:100% ;background: gray;margin-top:5px">
<input type="text" class="TEER" maxlength="20" id="item" style="height:35px;width:20%;padding:5px;" placeholder="Enter title , ex (basic information) " name="sec4" value="Works">
<input class="ed" type="button" style="float:right;height:35px;width:100px;" value="Edit">
</h3>
<textarea name="sec4[asd]" style="height:200px"></textarea>
</div>
</div>
</div>
</form>
<script>
$(function() {
$("#accordion").accordion({
collapsible: true,
active: false,
height: 'fill',
header: "h3",
update: function(event, ui) {
var order = $("#accordion").sortable("toArray");
$('#image_order').val(order.join(","));
alert($('#image_order').val());
}
}).sortable({
items: '.s_panel'
});
});
</script>
<script type="text/javascript">
$(function ahmed() {
$("#btnSerialize").on("click", function() {
var obj = $('form').serializeJSON();
console.log(obj);
var jsonString = JSON.stringify(obj);
$("#result").val(jsonString);
var xht = new XMLHttpRequest();
xht.open("POST", "save.php");
xht.setRequestHeader("Content-Type", "Application/json");
xht.send(jsonString);
})
});
</script>
在save.php
我使用以下代码:
$json=file_get_contents('php://input');
我无法打印save.php
页面上的内容。
我错过了什么?如何在save.php
文件中显示 HTML 表单的输出?
解决方案
推荐阅读
- python - 如何在python中删除字符串周围的引号?
- java - 从javaFX中的数据库生成PDF调用信息
- android - 在某些 Android 设备上获取 nullPointerException onStart() 方法
- objective-c - 使用 Realm 查询嵌套对象数组的属性
- python - 获取所有房间的列表(Django 频道 2)
- go - 监听和服务的 Goroutine 阻塞主进程的执行,永远不会达到用于通信的以下选择状态
- php - 类内的 MySQLi 语句
- scala - 在 url 中写入 uri 模式
- python - 在 python 中运行使用 pyinstaller 和 Google Cloud API 集成构建的 exe 文件时出现错误
- google-sheets - 过滤,如果结果为 x,则替换为 y,或者如果结果为 a,则替换为 b