【问题标题】:How do post method works in phppost方法如何在php中工作
【发布时间】:2020-01-28 23:15:50
【问题描述】:

我该如何解决这个问题?

//error_reporting(0);
$token = $_POST['token'];
$invite = $_POST['invite'];

$url = "https://mywebsite.com/asd/".$invite."";
$dingaling = "$token"

?>

时间:https://mywebsite.com/asdsdsss.php?token=test&invite=test2

错误:

注意:未定义索引:第 3 行 D:\asdsdsss.php 中的标记

注意:未定义索引:在 D:\asdsdsss.php 第 4 行邀请

【问题讨论】:

  • $_POST 不是一种方法。它是一个关联数组,包含从客户端请求的帖子正文到您的端点的查询字符串值。您提供的 url 在 url 中有查询字符串,它将被解析为 $_GET 关联数组,而不是 $_POSTphp.net/manual/en/reserved.variables.post.phpphp.net/manual/en/reserved.variables.get.php
  • @Taplar 现在当我通过 javascript 发布帖子时它不起作用。
  • 你提交表单了吗?
  • @VinayKaklotar 在这里:让 xhttp = new XMLHttpRequest(); xhttp.open("POST", "asdsdsss.php", true); xhttp.setRequestHeader("内容类型", "application/x-www-form-urlencoded"); xhttp.send("token=" + thetokenbruh + "&invite=" + theinvitebruh);
  • @dawaeboi 你应该试试ajax

标签: javascript php arrays post http-post


【解决方案1】:

用 ajax 试试

您可以在 post 方法中使用 ajax 发送数据。

$.ajax({
    url: 'asdsdsss.php',
    contentType: 'application/json',
    dataType: 'json',
    type: 'POST',
    data: {
        "token": thetokenbruh,
        "invite": theinvitebruh
    },
    success: function (data) {

    },
    error: function (errordata) {

    }
});

PHP 代码 (asdsdsss.php)

<?php
//error_reporting(0);
if ($_POST) {
    $token = '';
    if (isset($_POST['token'])) {
        $token = $_POST['token'];
    }

    $invite = '';
    if (isset($_POST['invite'])) {
        $invite = $_POST['invite'];
    }

    $url = "https://mywebsite.com/asd/" . $invite . "";
    $dingaling = "$token";
}
?>

【讨论】:

    猜你喜欢
    • 2019-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-01
    • 2023-03-28
    • 1970-01-01
    • 2020-03-21
    相关资源
    最近更新 更多