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はずです。ObjectArray

次のようなものを試してください:

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

の説明については、http://api.jquery.com/jQuery.post/を参照してください$.post

于 2013-07-05T14:57:31.803 に答える