Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have this array in javascript:

arr = [1, "string", 3]

And this, my ajax call:

$.post("./ajax_book_client.php",
        {'client_info[]': arr},
    function(data) {
          // some stuffs here
        }
});

Here's the php excerpt:

<?php 
    $arr = $_POST['client_info'];

    // I want to access the array, indexed, like this:
    $arr[0] = 2;
    $arr[1] = "Hello";
    $arr[2] = 10000;

?>

But I get this error:

Uncaught TypeError: Illegal invocation jquery-1.8.3.min.js:2

What's the correct way to do this? Thanks!

share|improve this question

4 Answers 4

Remove } from }); to remove syntax error.

Also no need to use [] with client_info so you can remove it.

Use:

<script>
var arr = [1, "string", 3];
$.post("./ajax_book_client.php",
        {'client_info': arr},
    function(data) {
          // some stuffs here
        }
);
</script>

ajax_book_client.php

<?php 
    $arr = $_POST['client_info'];

    echo $arr[0];
    echo $arr[1];
    echo $arr[2];
?>
share|improve this answer

extra braces, change:

$.post("./ajax_book_client.php",
        {'client_info[]': arr},
    function(data) {
          // some stuffs here
        }
});

to

$.post("./ajax_book_client.php",
        {'client_info[]': arr},
    function(data) {
          // some stuffs here
       // } <--remove this
});
share|improve this answer

You have a syntax error in your JS. Remove one }.

share|improve this answer

Remove client_info[] to client_info and extra brace

Try

<script>
var arr = [1, "string", 3];
$.post("./ajax_book_client.php",
    {'client_info': arr},
    function(data) {
      // some stuffs here
    }
);
</script>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.