我是后台的新手,试图构建REST API。我无法从ajax调用中检索我的请求数据。REST API学习曲线
<?php
$logfile = fopen("log.txt", "w");
fwrite($logfile, "testing\n");
$method = $_SERVER['REQUEST_METHOD'];
$request = explode('/', trim($_SERVER['PATH_INFO'],'/'));
$input = json_decode(file_get_contents('php://input'),true);
$req_dump = print_r($input, true);
fwrite($logfile, $req_dump . "\n");
fclose($logfile);
?>
我的电话是这样的:
$.ajax({
dataType: "json",
type: "GET",
url: "http://example.com/api.php",
data: {data:"data"},
success: function(){ console.log('success'); }
});
我log.txt文件只是被“测试”一文,但没有指示传递的对象{数据:“数据”}。我在这里跳过哪些步骤?
你看过浏览器开发工具中的AJAX请求/响应了吗?你有没有在项目中包含jQuery库?是否有任何错误报告?你在网络服务器上运行这个吗? –
尝试使用类似https://www.getpostman.com/ – cmnardi
的工具调用此php脚本,并删除脚本 – cmnardi