<form action:"" name="sample" method="post"/>
Firstname:<input type="text" name="firstname" /><br>
Lastname:<input type="text" name="lastname"/><br>
DOB:<input id="datepicker" /><br>
Email:<input type="text" name="email"/><br>
Gender:
<input type="radio" name="Male" value="Male"/> Male
<input type="radio" name="Female" value="Female"/> Female<br>
Address: <textarea name="address" rows="2" cols="20"></textarea><br>
<input type="submit" value="Submit" />
</form>
我需要像
这样的json输出 {"Firstname":"","Lastname":"","Email":"","Address":""}
答案 0 :(得分:1)
您可以按如下方式获得所需的JSON:
var obj = new Object();
obj.FirstName="first";
obj.LastName="Last";
obj.DOB="1/1/1990";
obj.Gender="Male";
obj.Address="Test Address";
alert(JSON.stringify(obj));
答案 1 :(得分:0)
<?php
//We have a post
if ($_POST) {
$data = json_encode($_POST);
var_dump($data);
}
答案 2 :(得分:0)
如果你想将它发布为json对象,那么你可以使用jQuery(参见第二个链接)。