1. Return json string:
$.ajax({
data:{
"shipmmsi":shipmmsi,
"shipname":shipname
},
url : "shipbk/findShipMMSIAndName.do",
async : true,
type : "POST",
success : function(data) {
var ships = eval('(' data ')');
$("#bindShipmmsiDiv table tbody").html("");
if(ships!=null){
if(ships.length){
$("#bindShipmmsiDiv").show();
var trs="";
for(var i=0;i trs ="" ships[i].mmsi " | " ships[i].vesselName " |
";
}
$("#bindShipmmsiDiv table tbody").append(trs);
//给tr注册点击事件
$("#bindShipmmsiDiv table tbody tr").click(function(){
$(this).addClass('select_tr').siblings().removeClass('select_tr');
});
$("#bindShipmmsiDiv table tbody tr").dblclick(function(){
fillShipMMSIAndName(this);
$("#bindShipmmsiDiv").hide();
});
}
}
}
});
3、通过jquery的 $("form").serialize() 可以将form表单的数据序列化后提交到后台,因此通过ajax可以操作form表单并处理返回的数据。
$.ajax({
url : 'deliveryWarrant/update.do',
data : $('#myform').serialize(),
type : "POST",
success : function(data) {
var res = eval('(' data ')');
if (res && res.success == true) {
alert(res.message);
location.href="/godownWarrant/findToDeliveryWarrant.do?godownWarrant.code=" $("#myform input[name=godownWarrant\.code]").val();
} else {
alert(res.message);
}
}
});
4. Methods to prevent garbled characters:
jsp page: charset: utf-8
servlet:utf-8
filter:utf-8
Add
response.setCharacterEncoding(" before PrintWriter out = response.getWriter() UTF-8") can solve the problem of garbled characters.
But remember to put it before declaring PrintWwrite.
In short, the front-end interface, java files, databases and database connections all use unified encoding, so that there will be no garbled characters