$ .post()Jquery帖子没有使用新的数组()到PHP

I have the following jquery posting to a php page. A var_dump($_POST); on the php page returns null but if I do :

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

everything works.

The reason I do not want to do it that way, is because the array can have variable arguments. Any help?

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

Your var arr should be an Object not an Array.

Try something like:

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

See http://api.jquery.com/jQuery.post/ for explanation of $.post.