1

I have a php file that normally takes input array from an html multiple select box, and I need a way to post that data from JScript code in another file.

As I understand it, JQuery post would work nicely for this, however that will not work in IE. Is there any easy way to pass an array of values through JavaScript so that its contents can be accessed through the $_POST array, just as if they were from an HTML multiple select box AND works in IE?

1
  • 1
    What makes you think jQuery wouldn't work in IE? Commented Jul 18, 2011 at 19:14

4 Answers 4

2

however that will not work in IE

I don't know where this idea comes from. I can assure you that the jQuery's $.post method works more than perfectly fine in IE. For example:

var array = $('#multiSelectId').val();
$.post('/foo.php', { data: array }, function(result) {
    // TODO: process the results
});
Sign up to request clarification or add additional context in comments.

1 Comment

That idea came from here: api.jquery.com/jQuery.post ---- First Comment: "jQuery Post doesn't work in Internet Explorer is there any settings for this method", but if you're right I'll just go ahead and do it that way, thanks.
1

JavaScript side

 var arrayToPost= new Array(1, 2, 3);
    arrayToPost = JSON.stringify(arrayToPost );

will poste this string : [1,2,3]

PHP side

print_r(json_decode($_POST['arrayToPost']));

result :

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
)

Comments

0
$.post('/path/to/handler.php', $('form').serialize());

Comments

0

Have a look at xAjax, a nice PHP-libraty to simplify AJAX using PHP.

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.