如何POST一个JSON格式的数据给java接口,获得返回数据

2024-12-21 08:15:30
推荐回答(1个)
回答1:

$('#save').click(function(event) {
var jenis = $('#jenis').val();
var model = $('#model').val();
var harga = $('#harga').val();
var json = { "jenis" : jenis, "model" : model, "harga": harga};
$.ajax({
url: 'phone/save',
data: JSON.stringify(json),//这里设置json格式
type: "POST",
beforeSend: function(xhr) {
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
},
success: function(data){
alert(data);
}
});

event.preventDefault();
});