1

I have an array of javascript obejcts. I want to send this array to server. I tried :

JSON.stringify(jObectArray);

But at server side i am getting the empty array. How can i send it to server successfully ?

4
  • 4
    We can't see your array... edit: in fact we can't see how you're sending it either... Commented Oct 25, 2012 at 10:15
  • If you're using jQuery, try this: api.jquery.com/jQuery.ajax Commented Oct 25, 2012 at 10:17
  • More information is needed: the unknowns at present are (a) the contents of jObjectArray and (b) what the server is doing. Commented Oct 25, 2012 at 10:18
  • You didnt specify type in ajax (get or post) Commented Oct 25, 2012 at 10:21

3 Answers 3

2

Without seeing any of your code:

var arr = ["one","two","three"];
arr = JSON.stringify(arr);
$.ajax({
  url: "something.something",
  data: {
    theArray: arr
  },
  success: function(data) {
    //success
  }
});

EDIT:
What does your array look like...?

Sign up to request clarification or add additional context in comments.

1 Comment

You didnt specify 'type' in ajax ('get' or 'post')
1

You should make:

$.ajax({
   url :'urltoserver',
   data: { myArray : jObectArray },
   dataType: 'JSON'
 });

1 Comment

No doubt you'll have your answer accepted... fickle SO users... :(
0
$.ajax({
   url :'urltoserver',
   data: {'yourarray':JSON.stringify(jObectArray)},
   dataType: 'JSON',
   type:"POST"
 });

at server

print_r($_POST['yourarray']);

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.