Jsp 页面 AJAX success:function(response) 无法获取 response.responseText 返回值
前台代码:$.ajax({type:"get",url:"user!forAjax.action",data:"pid="+email,success:function(...
前台代码:
$.ajax({
type:"get",
url:"user!forAjax.action",
data:"pid="+email,
success:function(response){
if( response.responseText.equals("pass")){
alert( response.responseText);
showEmail.innerText = "✔";
}else{
alert( response.responseText);
showEmail.innerText = "已被注册";
}
}
java后台代码:
public void forAjax() throws Exception {
response2 = ServletActionContext.getResponse();
request2 = ServletActionContext.getRequest();
String str =request2.getParameter("pid");
response2.setContentType("text/html;charset=UTF-8");
String hql="";
String ss="";
if(str.indexOf("@")>-1){
hql="email";
ss=user.getEmail();
}else{
hql="phoneNo";
ss=user.getPhoneNo();
}
List<User> list=service.findbyHql(hql, ss);
try {
if (list.size()>1){
response2.getWriter().write("pass");
} else{
response2.getWriter().write("cut");
}
response2.getWriter().flush();
response2.getWriter().close();
} catch (IOException e) {
e.printStackTrace();
}
}
action 跳转没问题 展开
$.ajax({
type:"get",
url:"user!forAjax.action",
data:"pid="+email,
success:function(response){
if( response.responseText.equals("pass")){
alert( response.responseText);
showEmail.innerText = "✔";
}else{
alert( response.responseText);
showEmail.innerText = "已被注册";
}
}
java后台代码:
public void forAjax() throws Exception {
response2 = ServletActionContext.getResponse();
request2 = ServletActionContext.getRequest();
String str =request2.getParameter("pid");
response2.setContentType("text/html;charset=UTF-8");
String hql="";
String ss="";
if(str.indexOf("@")>-1){
hql="email";
ss=user.getEmail();
}else{
hql="phoneNo";
ss=user.getPhoneNo();
}
List<User> list=service.findbyHql(hql, ss);
try {
if (list.size()>1){
response2.getWriter().write("pass");
} else{
response2.getWriter().write("cut");
}
response2.getWriter().flush();
response2.getWriter().close();
} catch (IOException e) {
e.printStackTrace();
}
}
action 跳转没问题 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏20(财富值+成长值)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询