0

I have a combobox with textbox. here i need to create an object for an array in js through ajax. ex:

var countries = {};
countries.results = [
    {id:'ZM',name:'Us'},
    {id:'ZW',name:'Ksa'}
];

how can i create an object for an array through ajax,php?

3
  • Probably relevant: php.net/json_encode Commented Mar 17, 2012 at 5:33
  • You need to add more details to your question. Please see the FAQ for tips on how to ask a good question - stackoverflow.com/questions/how-to-ask Commented Mar 17, 2012 at 5:50
  • how i can add some more values to that variable('countries') dynamically.Like, countries.push('{id:'jp',name:'jphn'}'); But it not working. Commented Mar 17, 2012 at 5:56

1 Answer 1

1

If you want to add more values to countries.results array use

countries.results.push({id : "IN", name : "India"});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.