Annyce Davis

Davis Technology Consulting

  • Home
  • About Me
  • Blog
  • Courses
  • Newsletter

Passing HashMap as POST parameter

July 22, 2009 by Annyce Davis

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’].

Basic vi Commands

July 13, 2009 by Annyce Davis

Here are a few basic vi commands that I have found helpful in adding and deleting information in a file from the command line.

dd – delete a line
i – change to insert mode
/ – perform a search query
n – move to the next result in the search
:wq – save the file and exit

Javascript Object declared within another Object

July 10, 2009 by Annyce Davis

In order to declare a Javascript object inside another one you would need to enter code similar to what is below.


var book = {
title: 'Nothing new!',
author: {name: 'Annyce', email:'annyce@gmail.com'}
};

You could then reference the author’s name via:
book.author.name

and if you wanted to update the name of the author, you would use
book.author.name = ‘Sarah’;

This feature of Javascript becomes very useful when you attempt to create an object with default settings and so forth.

Case Insensitive jQuery :contains Selector

June 26, 2009 by Annyce Davis

This is useful because for some reason the :contains selector in jQuery is not case-insensitive. BTW the code below works with jQuery 1.3.


jQuery.expr[':'].contains = function(a,i,m){
return jQuery(a).text().toUpperCase()
.indexOf(m[3].toUpperCase())>=0;
};
« Previous Page
Next Page »

Follow Me

  • Bluesky

Categories

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

Follow Me

  • Bluesky

Copyright © 2025 · All Rights Reserved · Log in