1. Use ajax
The jsp code is as follows:
Copy codeThe Code is as follows:
$. 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 );
}
});
2. Use the getJSON method:
Copy codeThe Code is as follows:
$. 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 );
}
});
The two types of actions return strings in the form of JSONArray array, and return array. toJSONString ();