gpt4 book ai didi

php - 如何在php中使用delete方法获取ajax发送的值

转载 作者:行者123 更新时间:2023-11-29 16:01:49 25 4
gpt4 key购买 nike

我的 php api 中有两个 IF 来检查请求方法是 POST 还是 DELTE 。对于 Post 方法,我使用 $_POST 获取 ajax 的“数据”部分中的变量。但对于 DELETE 方法我不能这样做。我使用了下面的代码

$deleteAcKey = file_get_contents("php://input");
$test = array();
parse_str($deleteAcKey, $test);
echo json_encode($test);

但是我得到了一些不可读的数据。我想要一些 json 数据,我可以使用 result.message 在 Ajax 中访问它

有什么建议吗?还有其他使用方法吗?

最佳答案

POST 请求和 DELETE 请求之间存在差异。第一个具有 BODY 有效负载 - 第二个没有或至少不被视为标准。

A payload within a DELETE request message has no defined semantics;sending a payload body on a DELETE request might cause some existingimplementations to reject the request.

https://www.rfc-editor.org/rfc/rfc7231#section-4.3.5

您可以使用 DELETE 方法发送正文,但 99% 会被忽略。

在您的情况下,您应该使用查询参数。

关于php - 如何在php中使用delete方法获取ajax发送的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56128098/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com