Home > Web Front-end > JS Tutorial > struts2 jquery json implements asynchronous loading of data (self-written)_jquery

struts2 jquery json implements asynchronous loading of data (self-written)_jquery

WBOY
Release: 2016-05-16 17:31:22
Original
876 people have browsed it
Copy the code The code is as follows:

//When the page is initially loaded
$(document).ready (function(){
//Register a mouse click event for a button that gets a single value
$("#getMessage").click(function(){
$.getJSON("ceshi",function (data){
//The value of the message in Action can be obtained from data.message through the . operator
$("#message1").html("" data.message "");
});
});

//Send expression data to the server
$("#getabc").click( function(){
//Serialize the form data
var params = $("form").serialize();
//Use $.ajax({}) in jQuery; Ajax method
$.ajax({
url:"ceshi",
type:"POST",
data:params,
dataType:"json",
success:function (data){
//Add the obtained data to the display layer
//Get the data of the object using data.userInfo.property
$("#message2").append("
" data.message "
")
},
error:function(){
$("#message2" ).append("
" "Incorrect information" "
")
}
});
});


});
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