使用ajax将json传入后台数据只要设置dataType为json格式即可。
用法举例:
function addNewManufacturer() {
var name = $("#id-manuf-name").val();
var address = $("#id-manuf-address").val();
var phone = $("#id-manuf-phone").val();
//组装json
var sendInfo = {
Name: name,
Address: address,
Phone: phone
};
$.ajax({
type: "POST",
url: "/Home/Add",
dataType: "json",指定ajax传递参数为json
success: function (msg) {
if (msg) {
alert("Somebody" + name + " was added in list !");
location.reload(true);
} else {
alert("Cannot add to list !");
}
},
data: sendInfo
});
}