1

I am trying to pass the values of a Javascript array to a PHP URL through Ajax. Here is script array

<script>"Talent_Percentile.php?"+globalArray"</script>

Where globalArray is my Javascript array. When I alert this, I get

Talent_Percentile.php?eqt_param1=4.00,eqt_param2=4.00,eqt_param3=4.00

I know about string replace but I don't know how to use it on an array. I need an output like

Talent_Percentile.php?eqt_param1=4.00&eqt_param2=4.00&eqt_param3=4.00

Can someone help me?

2
  • which string do you want to use as array? post some codes what you've tried Commented Nov 28, 2012 at 7:26
  • Is this post all one sentence? Wowzzz. Commented Nov 28, 2012 at 7:26

3 Answers 3

1

I'd recommend encoding your array to JSON:

<script>
     var url = "Talent_Percentile.php?" + JSON.stringify(globalArray);
</script>

On the server side, use json_decode to decode the data.

1
var mystring = globalArray.join("&");
var url = "Talent_Percentile.php?" + mystring;
0

Generally, to apply a function to all elements of an array you should use map:

globalArray = globalArray.map(function(v) {
    return v.replace("old", "new");
});

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.