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?
-
1What makes you think jQuery wouldn't work in IE?Quentin– Quentin2011年07月18日 19:14:04 +00:00Commented Jul 18, 2011 at 19:14
4 Answers 4
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
});
1 Comment
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
$.post('/path/to/handler.php', $('form').serialize());
Comments
Have a look at xAjax, a nice PHP-libraty to simplify AJAX using PHP.