简体   繁体   中英

PHP Jquery Ajax - Get Url Param

I am working on an Ajax Login form. On the PHP processing page when the login is successful, there are 3 options to redirect the user.

<?php
// ------------------------------------------------------------
// PROCESS LOGIN FORM ON POSTBACK
// ------------------------------------------------------------

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    ...

    // 1. DEFAULT URL: default destination url from config
    $plLoginDestinationUrl = PL_DEFAULT_LOGIN_DESTINATION;

    // 2. RETURN URL: if return address present in url
    if (isset($_GET['ReturnUrl'])) {
        $plLoginDestinationUrl = $_GET['ReturnUrl'];
    }

    // 3. PER USER URL: if custom user destination in db exists
    if ($pllogin->loginDestinationUrl != 'default') {
        $plLoginDestinationUrl = $pllogin->loginDestinationUrl;
    }
}

If the form is submitted without javascript (jquery), everything works fine. Submitting the page with ajax fails on #2. It just won't parse the $_GET['ReturnUrl'].

The PHP error response I always get when submitting with ajax is: Notice: Undefined index: ReturnUrl in.

Ajax is most likely POSTing not GETing. Try and replace $_GET['ReturnUrl']; to $_POST['ReturnUrl']; or even $_REQUEST['ReturnUrl'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM