0

I have an associative array

var order = [];
order['id'] = 1266;
order['customer'] = [];
order['customer']["firstName"] = "John";
order['customer']["lastName"] = "Doe";
order['customer']["age"] = 46;

I want to send this array as data into my ajax call

$.ajax({
     url : 'http:example.com',
     method : 'post',
     dataType : 'json',
     data : order,
     success : function() {
     }
})

Ajax are calling my url properly but sending empty data. I have tried

  1. JSON.stringify(order)
  2. data : {'order' : order}
  3. data : {'order' : JSON.stringify(order)}

But none of these are working

3

1 Answer 1

3

You just need to change the array to object. Instead of var order = []; use var order = {};

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

2 Comments

He should be using an object for this too: order['customer'] = {};
yeh, I got it. Thanks

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.