向指定URL发送json数据
$("#btnSend").click(function() {
$("#request-process-patent").html("正在提交数据,请勿关闭当前窗口...");
$.ajax({
type: "POST",
url: "RequestData.ashx",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(GetJsonData()),<!--使用这个jQuery封装的stringify,它可以将客户端发送的JSON数据对象进行序列化操作-->
dataType: "json",
success: function (message) {
if (message > 0) {
alert("请求已提交!我们会尽快与您取得联系");
}
},
error: function (message) {
$("#request-process-patent").html("提交数据失败!");
}
});
});
<!--使用这个方法来封装json对象-->
function GetJsonData() {
var json = {
"classid": 2,
"name": $("#tb_name").val(),
"zlclass": "测试类型1,测试类型2,测试类型3",
"pname": $("#tb_contact_people").val(),
"tel": $("#tb_contact_phone").val()
};
return json;
}
使用jQuery提交类似表单的信息
<!DOCTYPE html>
<html>
<head>
<script src="js/jquery.2.3.1">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$.post("example",
{
name:"张三",
city:"上海"
},
function(data,status){
alert("数据:" + data + "\n状态:" + status);
});
});
});
</script>
</head>
<body>
<button>点击发送 HTTP POST 请求,并获取状态信息</button>
</body>
</html>
(上面的代码为自己学习过程中的记录,如有雷同,算我抄你)