?
Solved

How to send a javascript associative array by Ajax

Posted on 2014-01-11
2
Medium Priority
?
1,718 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Suggested Courses

752 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