Home > Web Front-end > JS Tutorial > S2SH integrates JQuery Ajax to implement login verification function implementation code_jquery

S2SH integrates JQuery Ajax to implement login verification function implementation code_jquery

WBOY
Release: 2016-05-16 17:42:31
Original
1342 people have browsed it

Not much to say, code
action

Copy code The code is as follows:

package com.lk.action;
import javax.annotation.Resource;
import com.googlecode.jsonplugin.annotations.JSON;
import com.lk.service.StudentControl;
import com.opensymphony. xwork2.ActionSupport;
public class LoginAjaxAction extends ActionSupport {
private String username;
private StudentControl studentControl;
@JSON(serialize=false) //setStudentControl uses spring, which is very important, so that studentControl does not Serialization, if it is serialized, an error will be reported
public StudentControl getStudentControl() {//I have been looking for this error for a long time...ajax keeps returning error
return studentControl;
}
@Resource(name= "studentControl")
public void setStudentControl(StudentControl studentControl) {
this.studentControl = studentControl;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
@Override
public String execute() throws Exception {
if(studentControl.getStudentById(Integer.parseInt( username))!=null){
username = "User exists";
}else{
username = "User does not exist";
}

return "success";
}
}

The most important thing above is the @JSON(serialize=false). . . There are comments on it. . . .
struts.xml
Copy code The code is as follows:







What I want to say here is that json-default is inherited from struts-default....
login.html
Copy code The code is as follows:

//Moving in and out of the event focus bound to the user name
$("#un").bind({
focus:function(){
$(this).addClass("txtclick");
},
blur:function() {
var vtxt = $("#un").val();
if (vtxt.length == 0) {
$("#unerror").html("Username cannot be Empty");
$(this).removeClass("txtclick");
}else if(!isInteger(vtxt)){
//Check whether the username format is correct
$(" #unerror").html("Incorrect format!");
$(this).removeClass("txtclick");
}else{
$.ajax({
url : " loginAjax",
dataType : "json",
data : {
username : $(this).val(),
time : Math.random()*1000
},
success : function(data){
alert("success" data.username);
},
error : function(){
alert("error");
}
})
}
}
});

The above time: Math.random()*1000 has no practical significance, mainly to prevent cache from affecting asynchronous refresh . . . This is the first draft. The function has been implemented and can be modified later.
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