標籤:jquery json
$("#btnSend").click(function() {
$("#request-process-patent").html("正在提交資料,請勿關閉當前視窗...");
$.ajax({
type: "POST",
url: "RequestData.ashx",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(GetJsonData()),
dataType: "json",
success: function (message) {
if (message > 0) {
alert("請求已提交!我們會儘快與您取得聯絡");
}
},
error: function (message) {
$("#request-process-patent").html("提交資料失敗!");
}
});
});
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;
}
核心為JSON.stringify()方法,方法說明:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
參考文章:http://www.cnblogs.com/jaxu/p/3698404.html
本文出自 “java程式猿的部落格” 部落格,請務必保留此出處http://chengxuyuan.blog.51cto.com/5789198/1864856
JQuery提交JSON string資料