[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to send a javascript associative array by Ajax

Posted on 2014-01-11
2
Medium Priority
?
1,790 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

649 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