JQuery Forms Param

From CoderLearner
Jump to: navigation, search

Description

$.param() method creates a serialized representation of an object or array that can be used in a URL query string or Ajax.

Syntax

$.param(  obj )
$.param(  obj, traditional )

Example 1

<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Blur</title>
	<script 
		type="text/javascript" 
	src="jquery.min.js">				 
	</script>
	<script>
	    $().ready(function() {
                var url_data= { id:40, cs:44, val:300 };
                var str = $.param(url_data);
                $('#result').text(str);
	    });
        </script>
<head>
<body>
  <div id="result"></div>
</body>
</html>

Output

id=40&cs=44&val=300

Example 2

$.param({ a: [2,3,4] }) // "a=2&a=3&a=4"

$.param({ a: { b:1,c:2 }, d: [3,4,{ e:5 }] }) // "a[b]=1&a[c]=2&d[]=3&d[]=4&d[2][e]=5"