jquery ajax form serialize() 转json 数据,post 后台
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json
免费下载资源
·
$(".submit").click(function (){
$.ajaxSetup({
contentType: "application/x-www-form-urlencoded; charset=utf-8"
});
var DataDeal = {
formToJson: function (data) {
data=data.replace(/&/g,"\",\"");
data=data.replace(/=/g,"\":\"");
data="{\""+data+"\"}";
return data;
},
};
var userId = $('.userId').val();
var data =$("#addUserAddressJson").serialize();//获取值
data= decodeURIComponent(data,true);//防止中文乱码
var json=DataDeal.formToJson(data);//转化为json
var url = "${ctx}/address/addUserAddressJson";
$.ajax({
type : "POST",
url : url,
dataType : "text",
contentType : "application/json",
data :json,
success : function(data) {
if(data== "fail"){
window.location.href = "${ctx}/login?url=" + data;
}
if (data== "success") {
window.location.href = "${ctx}/address/getAddressList?userId="+userId;
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
}
});
});
$.ajaxSetup({
contentType: "application/x-www-form-urlencoded; charset=utf-8"
});
var DataDeal = {
formToJson: function (data) {
data=data.replace(/&/g,"\",\"");
data=data.replace(/=/g,"\":\"");
data="{\""+data+"\"}";
return data;
},
};
var userId = $('.userId').val();
var data =$("#addUserAddressJson").serialize();//获取值
data= decodeURIComponent(data,true);//防止中文乱码
var json=DataDeal.formToJson(data);//转化为json
var url = "${ctx}/address/addUserAddressJson";
$.ajax({
type : "POST",
url : url,
dataType : "text",
contentType : "application/json",
data :json,
success : function(data) {
if(data== "fail"){
window.location.href = "${ctx}/login?url=" + data;
}
if (data== "success") {
window.location.href = "${ctx}/address/getAddressList?userId="+userId;
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
}
});
});
GitHub 加速计划 / js / json
41.72 K
6.61 K
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:1 个月前 )
960b763e
3 个月前
8c391e04
6 个月前
更多推荐
已为社区贡献1条内容
所有评论(0)