Solved

How to send a javascript associative array by Ajax

Posted on 2014-01-11
2
1,469 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
Comment Utility
replace : var assoc_array = new Array();
by : var assoc_array = {};
0
 
LVL 15

Author Closing Comment

by:gplana
Comment Utility
Excellent. It works!

Thank you very much.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Importing and exporting data Magento 1.x ? 4 31
C3-->D3 Line Chart 4 17
angularls and plnkr 14 17
Problem to page 4 16
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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…

744 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

13 Experts available now in Live!

Get 1:1 Help Now