2

我将以下 jquery 发布到 php 页面。var_dump($_POST);php 页面上的A返回 null 但如果我这样做:

$.post("test.php", {"script" : script} );

一切正常。

我不想那样做的原因是数组可以有可变参数。有什么帮助吗?

var arr = new Array();
arr["script"] = scrip;
arr["account"] = "max@hotmail.com";
arr["accounttag"] = "TH";


if (follow != "")
    arr["followtag"] = follow;
if (join != null)
    arr["join"] = join;

$.post("test.php", arr );

    //{"script" : script, "account" : "max@hotmail.com", "accounttag" : "TH"}  
    //works if used instead of arr

    ///test.php

    var_dump($_POST)
    array 0{null};
4

1 回答 1

3

var arr应该是一个Objectnot Array

尝试类似:

var data = {
    script: scrip,
    account: "max@hotmail.com",
    accounttag: "TH"
}

if (follow != "")
    data.followtag = follow;
if (join != null)
    data.join = join;

$.post("test.php", data);

有关. _ _$.post

于 2013-07-05T14:57:31.803 回答