How to send a javascript associative array by Ajax

Posted on 2014-01-11
Medium Priority
Last Modified: 2014-01-11

I have an associative array (an object with properties, implemented by an array object) which I would like to send by AJAX using jquery.

I have this sniped of code:

	var params = {
			'assoc_array': assoc_array,
			'another_param': 'blah blah',

		url: "my_url.php",
		data: params,
		type: 'post',

Open in new window

the array is declared and filled this way:
var assoc_array = new Array(); 

function add_element(name,value){

Open in new window

I can see on firebug that only the other parameter is send by post, but not the assoc_array parameter. Why?

Question by:gplana
LVL 83

Accepted Solution

leakim971 earned 2000 total points
ID: 39773257
replace : var assoc_array = new Array();
by : var assoc_array = {};
LVL 15

Author Closing Comment

ID: 39773293
Excellent. It works!

Thank you very much.

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

586 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question