我创建了一个表单并将其内容序列化为JSON。我是json的新手。我想做的是通过POST将json发送到网址,但我不知道如何去做。这是我的代码
<h1>Register</h1>
<form class = "myform" method="get">
Name:<br />
<input type="text" name="name" value="" />
<br /><br />
Phone Number:<br />
<input type="text" name="telephone" value="" />
<br /><br />
Location:<br />
<input type = "text" name = "location" value="" />
<br /><br />
Logo:<br />
<input type = "text" name = "logo" value="" />
<br /><br />
Website:<br />
<input type = "text" name = "website" value="" />
<br /><br />
Email:<br />
<input type = "text" name = "email" value="" />
<br /><br />
Category:<br />
<input type = "text" name = "category" value="" />
<br /><br />
Postal:<br />
<input type = "text" name = "postal" value="" />
<br /><br />
Description:<br />
<input type = "text" name = "description" value="" />
<br /><br />
GPS:<br />
<input type = "text" name = "gps" value="" />
<br /><br />
Tags:<br />
<input type = "text" name = "tags" value="" />
<br /><br />
Advert:<br />
<input type = "text" name = "advert" value="" />
<br /><br />
Facebook:<br />
<input type = "text" name = "facebook" value="" />
<br /><br />
Twitter:<br />
<input type = "text" name = "twitter" value="" />
<br /><br />
Google:<br />
<input type = "text" name = "google" value="" />
<br /><br />
<input type="submit" value="Submit" />
</form>
<script src="jquery-1.11.1.min.js"></script>
<script>
var frm = $(document.myform);
var data = JSON.stringify(frm.serializeArray());
console.log(data);
</script>
那么我该如何将其发布到网址呢? (假设网址是www.me.com)
答案 0 :(得分:1)
您好,您可以使用ajax调用发送json数据
jQuery.ajax(
{
url : getPostData.php,
type: 'POST',
dataType : "json",
data: data,
success:function(data) { alert(data); },
error: function() {alert(data); }
}
);