Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我仍在努力将JSON数据传递到另一个页面。你知道怎么做吗?_Php_Ajax_Json - Fatal编程技术网

Php 我仍在努力将JSON数据传递到另一个页面。你知道怎么做吗?

Php 我仍在努力将JSON数据传递到另一个页面。你知道怎么做吗?,php,ajax,json,Php,Ajax,Json,请原谅我发了太多的帖子 当用户单击btnValidate按钮时,将调用Web服务。这是代码: $("#btnValidate").click(function() { // Creating variables to hold data from textboxes var uname = $("#user").val(); var upass = $("#pass").val(); $.post("Authorize.php", { data: JSON.stringify({

请原谅我发了太多的帖子

当用户单击btnValidate按钮时,将调用Web服务。这是代码:

$("#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>
到目前为止还不错。但是,我们要做的是将TokenId、LoginName、Created、Expires、Token、LastUsed中的值传递给一个名为listAll.php的页面

将这些值传递给listAll.php的想法是,我们可以处理它们,以及其他表单字段,并提交到数据库

我花了很多时间在谷歌上搜索答案,但到目前为止还没有找到任何可用的解决方案

我最接近的解决方案是data.Value.Token

很明显,因为JSON结构位于名为data的变量中,但我还没有弄清楚如何将其传递到listAll.php页面

此外,data.Value.Token将只传递tokenId的值

任何关于如何将与数据变量相关的值传递到listAll.php的想法都将不胜感激

  <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>

用户名:
密码:


您可以使用会话将数组传递到另一个页面

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

在后端脚本Authorize.php中,应该将令牌存储到会话中

js

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;

您需要在查询字符串中传递它,或者切换到
POST.hi@SLaks,请查看我刚才添加到上面帖子中的附加标记。我想我的问题是,如何将其添加到表单中,以便当我单击按钮时,它被传递到listAll.php,然后我可以从那里获取值?感谢您的及时回复。创建
元素。请注意,您从客户端传递的任何数据都是不可信的。@Nambi,我向所有人道歉。我被送到了场外。需要记住的一点是Authorize.php只指向Web服务。我希望从你们这些超级家伙那里得到的是一种获取TokinId、LoginName等值并传递到ListAll.php的方法。这就是要插入到数据库中的内容将被处理的地方,我想将TokenId和其余数据存储到json数据变量中。谢谢大家的帮助。
$("#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;
    });
});
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;