Home > Web Front-end > JS Tutorial > body text

jquery asynchronous request example code_jquery

WBOY
Release: 2016-05-16 18:05:48
Original
890 people have browsed it
1. Use ajax

The jsp code is as follows:
Copy the code The 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 getJSON method:
Copy the code The 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 organization form of the string returned by the two Actions can be in the form of JSONArray array, returning an array. toJSONString();
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template