ajax param() method
Translation results:
param
parameter
ajax param() methodsyntax
Function: The param() method creates a serialized representation of an array or object. This serialized value can be used in the URL query string when making AJAX requests.
Syntax: jQuery.param(object,traditional)
##Parameters:
Description | |
The array or object to be serialized. | |
Specifies whether to use the traditional method for shallow serialization (parameter serialization). |
Description: The param() method is used to internally convert the element value into a serialized string representation. See .serialize() for more information. For jQuery 1.3, if the passed parameter is a function, then using .param() will get the return value of the function instead of returning the function as a string. For jQuery 1.4, the .param() method will serialize objects through deep recursion to meet the needs of modern scripting languages, such as PHP, Ruby on Rails, etc. You can disable this feature globally by setting jQuery.ajaxSettings.traditional = true; If the object being passed is in an array, it must be an object array in the format of the return value of .serializeArray(): [{name:"first",value:"Rick"},{name:"last",value: "Astley"},{name:"job",value:"Rock Star"}]
ajax param() methodexample
<html> <head> <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ personObj=new Object(); personObj.firstname="Bill"; personObj.lastname="Gates"; personObj.age=60; personObj.eyecolor="blue"; $("button").click(function(){ $("div").text($.param(personObj)); }); }); </script> </head> <body> <button>序列化对象</button> <div></div> </body> </html>
Click the "Run instance" button to view the online instance