如何将$_GET变量传递给.load php文件


How to pass $_GET variable to a .load php file

我有一个JavaScript函数将main-section.php加载到profile.php

    $(".profile-click").click(function(e){
    e.preventDefault();
        $id = $(this).attr("id");
        switch($id){strong text
            case "main-click":
            $("#information-container").load("profile/main-section.php");
            break;
        }
    });

当用户在main-section.php中出现错误时,我想显示一些文本,所以我自然会尝试发送$_GET['']变量,但它不会显示在我的main-section.php

我试着通过window.location.href='../profile.php?error=short_username';发送,虽然这不起作用,把它发送到main-section.php?error=short_username发送到错误的页面

试着像这样发送你的数据:

$("#information-container").load("profile/main-section.php?variable=my_data&another_variable=another_value");

通过将变量附加到URL中。

然后你可以在main-section.php

上使用
echo $_GET['variable']; // my_data
echo $_GET['another_variable'] // another value

你也可能想使用isset来确保变量在使用它们之前被定义。

:

if ( isset( $_GET['variable' ) ) {
   echo $_GET['variable'];
}