SoFunction
Updated on 2025-04-07

jquery asynchronous request instance code

1. Use ajax

The jsp code is as follows:
Copy the codeThe code is as follows:

$.ajax({
type:"get",
dataType:"json",
url:"<%=basePath%>?method=getUserMsgByUserId",
data:"userId="+userId,
success:function(msg){
var data = eval("("++")");
alert($("#userName").val());
$("#userName").val(data[0].userName);

}
});

2. Use getJSON method:
Copy the 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 organizational forms of returning strings that can use the JSONArray array to return ();