簡體   English   中英

通過jquery ajax傳遞一個php數組

[英]passing a php array through jquery ajax

我想通過ajax傳遞一個數組,但不知道我會怎么做。

<input type="button" data-array="'.$array.'" id="button" value="click">

我知道我不能把數組放在html中,但我無法想到如何解釋我想要實現的目標。

$('#button').click(function(){
    array = $(this).attr('data-array');
    $.ajax({        
        type    : 'POST',
        dataType : 'json',
        url     : 'ajax.php',
        data    : 'array='+array,
        success : function(data) {
            $('#result').html(data);
        }
    });
});

所以我想把那個數組變量$ array傳遞給ajax.php。 這是否可能,如果是這樣,它是如何完成的? 我猜想和json有什么關系?

您可以將它存儲在會話變量中,並在需要時稍后調用它,而不是將數組存儲在html中。

$_SESSION['dataArray'] = $array;

暫無
暫無

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

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