簡體   English   中英

$ .post Jquery發送數組

[英]$.post Jquery send array

我在$ .post中發送數組到php有問題。 var_dump結果為“NULL”JSON.stringify不起作用..

JQUERY

var photobox = []; 

photobox.push(e.target.result); 

$.post("../modules/upload.php",{"images[]" : photobox, count : sum},
                   function(data)
                    {
                        $('.list').prepend(data);
                    }).done(function() {
    $('#files').prop('disabled', false);
    $('.file-search').html("Szukaj...");
    $(".img-thumbnail").removeClass("first");
    $(".img-thumbnail").first().addClass("first");

e.target.result是base64代碼

PHP

$images = $_POST['images'];
var_dump($images);

你可以像這樣發送數組:

$.post('/thepage.php', {'NameOfKey': variableName});

上面的代碼將允許VariableName成為一個數組。

您需要在客戶端上編碼為JSON,但是當您在服務器(PHP)上使用json_decode將其轉換回數組時: http ://php.net/manual/en/function.json-decode.php

暫無
暫無

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

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