【发布时间】:2015-08-26 02:14:19
【问题描述】:
我正在尝试使用此 php 代码接收和打印 json:
<?php
$data = json_decode(file_get_contents('php://input'), true);
print_r($data);
?>
我没有接收或打印任何数据。但如果我使用这个 ajax:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> </script>
<script>
(function($){
function processForm( e ){
$.ajax({
url:'http://mydyndns:8010/has/input_parameters_startReg.php',
dataType: 'json',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({ DeviceID: 23, ForceReg: 0, StartTime: "10/06/2015 17:45"}),
success: function (data) {
},
error: function (e) {
alert(e.responseText);
},
});
e.preventDefault();
}
$('#my-form').submit( processForm );
})(jQuery);
它正在工作,我在浏览器中打印了发布的数据。如何更改我的 php,以便从浏览器直接点击会给我 ajax 给出的结果?
【问题讨论】:
-
您是否将任何参数传递给第一个脚本?我的意思是,你像 test.php?a=123 一样运行它吗?如果你不向它发送任何输入,它就不会输出任何东西
-
是的,我正在这样运行它:mydyndns/has/input_parameters_startReg.php?StartTime=10/06/… 但我什么也没得到
-
看来php://input 只读取POST 数据as written here
-
那么有没有一种方法或其他功能可以与 GET 方法一起使用?
-
this 可能有助于了解发生了什么