我仍在努力将JSON数据传递到另一个页面。 任何想法如何做到这一点?

Please forgive me for too many posts.

When a user clicks the btnValidate button, a call is made to a webservice. Here is that code:

$("#btnValidate").click(function() {

// Creating variables to hold data from textboxes

var uname = $("#user").val();
var upass = $("#pass").val();

$.post("Authorize.php",
    { data: JSON.stringify({ LoginName: uname,Password: upass }) },
    function( data )
    {
        var result = JSON.parse( data );
        if ( result != null && result.Status != null && result.Status == 0 )
        {
            // if the result was valid and the Status was 0 ("success") then login succeeded
            location.href = "listAll.php";
            return;
        }
        // analyze what went wrong:
        if ( result == null )
        {
            alert( "Invalid JSON result from validation request" );
        } else if ( result.Status == null ) {
            alert( "No Status field found in JSON result from validation request" );
        } else {
            alert( "Invalid username or password. Please try again." );
        }
     }
    );

});
</script>

The webservice in return, response with the following values:

{
    "Value": {
        "TokenId": 11,
        "LoginName": "Jerry.Mann",
        "Created": "2013-12-10T15:44:49",
        "Expires": "2013-12-31T15:44:49",
        "Token": "61f5da50-d0d9-4326-a403-f8e4798c0f0d",
        "LastUsed": "2013-12-10T15:44:49"
    },
    "Status": 0,
    "Message": null
}

So far so good. However, what we would like to do is pass the values in TokenId, LoginName, Created, Expires, Token, LastUsed to a page called listAll.php.

The idea of passing these values to listAll.php is so we can process them, along with other form fields and submit to the database.

I have spent a lot of time googling for answers but have not found any usable solutions so far.

The closest I came to a solution is something called data.Value.Token

Obvious because JSON structure is in a variable named data but I have not figured out how to pass this to the listAll.php page.

Beside, data.Value.Token will only pass values for tokenId.

Any ideas on how to pass the values associated with data variable to listAll.php will be greatly appreciated.

  <form id="Form1" method="get" >

    <table cellpadding="0" cellspacing="0" border="0">
      <tr>
              <td class="label" nowrap><label for="user">UserName:</label></td>
                <td class="field">
                  <input  maxlength="40" class="required" name="user" id="user" size="20" type="text" tabindex="2" value="" style="width:400px;color:#999;font-size:9pt;height:20px;" />
                </td>
              </tr>
              <tr>
                <td class="label" nowrap><label for="pass">Password:</label></td>
                <td class="field">
                  <input  maxlength="40" class="required" name="pass" id="pass" size="20" type="text" tabindex="3" value="" style="width:400px;color:#999;font-size:9pt;height:20px;" />
                </td>
      </tr>
      <tr>
        <td></td>
        <td>
          <div class="buttonSubmit">
            <span></span>
                        <input type="button" id="btnValidate"
                            style="width: 180px" value="Log In" />

          </div><br clear="all"/>

        </td>
      </tr>
    </table>

you may use session to pass the array to the another page.

session_start();
$JsonResult = $_SESSION['result']

In your backend script, Authorize.php, you should store token into session.

js

$("#btnValidate").click(function(){
    $.post('Authorize.php', {$('#form').serialize()}, function(data) {
        try {
            data = JSON.parse(data);
        } catch (e) {
            return false;
        }
        if (data && 'ok' == data.result) {
            top.location = 'listAll.php';
        }
        return false;
    });
});

Authorize.php

if (empty($_POST) || isset($_POST['pass']) || !isset($_POST['login'])) {
    exit;
}

/*
 * some authorize logic
 */
if ($authorized) {
    session_start();
    $_SESSION['token'] = $token;
    echo json_encode(array('result' => 'ok'));
}
exit;