0

I am using jQuery and PHP. I have a JavaScript array, when I pass it to the server and try to retrieve the array, I can only get the last element. Why is that and how can I get my array values properly?

JavaScript:

var arr = [] ;
arr.push("kanishka");
arr.push("bandara");

jQuery.ajax({
  type: "post",
  url: baseurl+"profile/mprofile/action/ratings/add_ratings",
  data:{ "arr":arr},
  success: function(data, status) {  
    jQuery('#header-error').html(data);
  } 
}); 

PHP:

$arr = $this->ci->input->post('arr');
pre($arr); 
die;

Result shown in FireBug:

<pre>bandara</pre>
0

1 Answer 1

3

Try this:

var arr = [] ;
arr.push("kanishka");
arr.push("bandara");

jQuery.ajax({
    type: "post",
    url: baseurl+"profile/mprofile/action/ratings/add_ratings",
    data:{ "arr":arr.serializeArray()},
    success: function(data, status) {  

        jQuery('#header-error').html(data);
    } 
}); 
Sign up to request clarification or add additional context in comments.

1 Comment

mm. it did not worked since i am using jquery 1.3.2 . i used JSON.stringify insted , thanks any way.

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.