簡體   English   中英

無法弄清楚如何將信息從一個發送到另一個。php 文件

[英]Can't figure out how to send information from one to another .php file

我正在嘗試通過 POST 發送一個數組,並通過 GET 從 first.php 到 second.php 文件發送一個數組,但我似乎無法讓它工作。 對於所有 3,我收到錯誤消息未定義索引

一、php

<?php
    session_start();

    $_SESSION["trys"] = 0;
    echo "<hr/><pre>".print_r($_SESSION, 1)."</pre><hr/>";
?>
<script>
//array
arrayIDs = [04, 05, 45, 45, 55]

$.ajax({
                url: 'second.php',
                type: 'post',
                data: {arrayIDs: arrayIDs},
                success: function(response){
                    console.log("POST !DELA!")
                }
            });

//string //x=0&y=9
url = "second.php?" + "x=" + x + "&y=" + y;
// I send it through get
</script>

<html>
//some tables data is generated from
</html>

二、php

<?php
    session_start();
    $kliknjenX =  $_GET["x"];
    $kliknjenY =  $_GET["y"];
    $kliknjenID = $kliknjenX + "" + $kliknjenY;

    $arrayIDs = $_POST['arrayIDs'];
?>

原因是您實際上從未在請求中發送任何GET數據......

<script>
//array
arrayIDs = [04, 05, 45, 45, 55]

$.ajax({
                url: 'second.php',               // <<-- This line doesn't have GET variables
                type: 'post',
                data: {arrayIDs: arrayIDs},
                success: function(response){
                    console.log("POST !DELA!")
                }
            });

url = "second.php?" + "x=" + x + "&y=" + y;       // <<-- This line does nothing
</script>

<html>
//some tables data is generated from
</html>

它應該是:

<script>
//array
var arrayIDs = [04, 05, 45, 45, 55];

var x = "some_url_encoded_value";
var y = "another_encoded_value";

var destination_url = "second.php?x=" + x + "&y=" + y;    

$.ajax({
                url: destination_url,
                type: 'post',
                data: {arrayIDs: arrayIDs},
                success: function(response){
                    console.log("POST !DELA!")
                }
            });


</script>

<html>
//some tables data is generated from
</html>

我認為這將幫助您測試它:

一、php

<?php
session_start();

$_SESSION["trys"] = 0;
echo "<hr/><pre>".print_r($_SESSION, 1)."</pre><hr/>";
?>

<script>
    arrayIDs = [04, 05, 45, 45, 55]

    $.ajax({
        url: 'second.php?x=0&y=9',
        type: 'post',
        data: {arrayIDs: arrayIDs},
        success: function(response){
            console.log("POST !DELA!")
        }
    });
</script>

<html>
//some tables data is generated from
</html>

二、php

<?php
    session_start();
    $kliknjenX =  $_GET["x"];
    $kliknjenY =  $_GET["y"];
    $kliknjenID = $kliknjenX + "" + $kliknjenY;

    $arrayIDs = $_POST['arrayIDs'];
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM