JQuery ajax serialize of method USES the example
- 2020-03-30 04:15:30
- OfStack
The.serialize() method creates a text string in standard url-encoded form. Its action object is a jQuery object that represents a collection of form elements.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/jscript">
// $(function () {
// alert($("form").serialize());
// })
function btnClick() {
alert($("form").serialize());
}
</script>
</head>
<body>
<form>
<div><input type="text" name="a" value="1" id="a" /></div>
<div><input type="text" name="b" value="2" id="b" /></div>
<div><input type="hidden" name="c" value="3" id="c" /></div>
<div>
<textarea name="d" rows="8" cols="40">4</textarea>
</div>
<div><select name="e">
<option value="5" selected="selected">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select></div>
<div>
<input type="checkbox" name="f" value="8" id="f" />
</div>
<div>
<input type="button" name="g" value=" submit " id="g" onclick="btnClick()" />
</div>
</form>
</body>
</html><span style="font-size:18px;color:#ff0000;">
</span>
Click submit:
The output standard query string: a=1&b=2&c=3&d=4&e=5
If the checkbox is also selected, the output is: a=1&b=2&c=3&d=4&e=5&f=8