2

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"] = "[email protected]";
arr["accounttag"] = "TH";


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

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

    //{"script" : script, "account" : "[email protected]", "accounttag" : "TH"}  
    //works if used instead of arr

    ///test.php

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

1 Answer 1

3

Your var arr should be an Object not an Array.

Try something like:

var data = {
    script: scrip,
    account: "[email protected]",
    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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.