1、用ajax
jsp代码如下:
$.ajax({
type: " get " ,
dataType: " json " ,
url: " <%=basePath%>actionSmUser.do?method=getUserMsgByUserId " ,
data: " userId= " + userId,
success: function (msg){
var data = eval( " ( " + msg.responseText + " ) " );
alert($( " #userName " ).val());
$( " #userName " ).val(data[ 0 ].userName);
}
});
type: " get " ,
dataType: " json " ,
url: " <%=basePath%>actionSmUser.do?method=getUserMsgByUserId " ,
data: " userId= " + userId,
success: function (msg){
var data = eval( " ( " + msg.responseText + " ) " );
alert($( " #userName " ).val());
$( " #userName " ).val(data[ 0 ].userName);
}
});
2、用getJSON方式:
$.getJSON(url,
function
(data){
if (data != null && data != "" ){
$( " #userIdInput " ).val(data[ 0 ].userId);
$( " #userNameInput " ).val(data[ 0 ].userName);
$( " #menusIdInput " ).val(data[ 0 ].menusId);
$( " #depIdInput " ).val(data[ 0 ].depId);
$( " #isValidInput " ).val(data[ 0 ].isValid);
$( " #userIdInput " ).attr( " disabled " , true );
}
});
if (data != null && data != "" ){
$( " #userIdInput " ).val(data[ 0 ].userId);
$( " #userNameInput " ).val(data[ 0 ].userName);
$( " #menusIdInput " ).val(data[ 0 ].menusId);
$( " #depIdInput " ).val(data[ 0 ].depId);
$( " #isValidInput " ).val(data[ 0 ].isValid);
$( " #userIdInput " ).attr( " disabled " , true );
}
});