Solved

How to send a javascript associative array by Ajax

Posted on 2014-01-11
2
1,521 Views
Last Modified: 2014-01-11
Hi.

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',
		 };

	$.ajax({
		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){
   assoc_array[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?

Thanks.
0
Comment
Question by:gplana
2 Comments
 
LVL 82

Accepted Solution

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

Author Closing Comment

by:gplana
ID: 39773293
Excellent. It works!

Thank you very much.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now