Convert JSON Object to String javascript

Jan 26, 2011

You can user browser native function JSON.stringify to do this

var foo = {};
foo.bar = "new property";
foo.baz = 3;

var jsonString = JSON.stringify(foo);

https://developer.mozilla.org/En/Using_JSON_in_Firefox

And IE8 also supports it - http://blogs.msdn.com/b/ie/archive/2008/09/10/native-json-in-ie8.aspx

Categories : JavaScript

jQuery Template plugin html in variables

Jan 25, 2011

If you pass html content in the template variables, you have to use format to make sure that the html content gets converted into real html elements.

See this Stack overflow post http://stackoverflow.com/questions/4570222/htmlentities-equivalent-in-jquery-template-plugin

And this documentation - http://api.jquery.com/template-tag-html/

Categories : JQuery   JavaScript

Javascript code equivalent to java i18n MessageFormat

Jan 25, 2011

Here is a Stack overflow post with javascript regex solution for this problem.

http://stackoverflow.com/questions/1353408/messageformat-in-javascript-parameters-in-localized-ui-strings

Categories : JavaScript

How to center a div inside a div

Jan 17, 2011

If you need to center a div within another div, here is the solution from Stack overflow post -

http://stackoverflow.com/questions/114543/how-to-center-div-in-div

Quoting example from the post below for quick reference,

<div id="outer">
  <div id="inner">Foo foo</div>
</div>
#inner {
  width: 50%;
  margin: 0 auto;
}
Categories : CSS   HTML

Handling cookies with java URLConnection

Jan 17, 2011

http://www.hccp.org/java-net-cookie-how-to.html

Same way you can set other headers like Content-Type, Accept to the HTTP request using the setRequestProperty method of URLConnection

Categories : HTTP   Java