Annyce Davis

ones and zeros

  • Home
  • Public Speaking
  • About Me
  • Courses
  • Life

Passing HashMap as POST parameter

July 22, 2009 by Annyce Davis Leave a Comment

If you would like to pass a hashmap as a parameter to a POST call in JavaScript, you need to use the dot notation and it will be interpreted as belonging to a hashmap. The code below loops through the properties of an object called ‘options’ and adds each one except for the toString() method to the POST parameter hashmap.

===================================================
Declaration of options variable

var options = {
foo: 'blah',
boo: 'muah',
toString: function() {
return this.foo + ', ' + this.boo;
}
};

===================================================
Inside AJAX call function

if (options != null) {
for (property in options) {
if (property != 'toString')
post_data['options.' + property] = options[property];
}
}

Using this code when you access the POST parameters on the server side, you can reference the ‘options’ POST parameter as a hashmap, i.e. options[‘foo’].

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)

Related

Filed Under: JavaScript

Follow Me

What engineering leaders need to know from this year’s Google I/O

I didn't intentionally aim to create a rhyming title, but there you have it. Each year, I look forward to Google I/O like a kid going back to school. This year … [Read More...]

Talk: The Real MVP

You have an idea for a new app. You've secured buy-in from the business. What's next? The MVP. But what does it take to ship a new app these days? What are the … [Read More...]

Categories

  • Android (55)
  • Career (2)
  • Communication (4)
  • Flutter (1)
  • Git (4)
  • Gradle (4)
  • Grails (23)
  • Java (8)
  • JavaScript (6)
  • Kotlin (17)
  • Life (4)
  • Public Speaking (23)
  • RxJava (1)
  • Software Development (7)
  • Twitter (3)
  • Uncategorized (11)
  • Video Course (5)

Copyright © 2023 · Beautiful Pro Theme on Genesis Framework · WordPress · Log in