处理通过 ajax 调用从 servlet 返回的“成功”字符串
Processing "success" string returned from servlet via ajax call
我有一个 servlet,它接受我的 ajax 请求,它将用户名和密码作为参数从我的 ExtJs 项目中的 LoginView 传递。这是相同的代码:
public class UserLoginController extends MultiActionController {
OrgTreeService orgTreeService;
ModelAndView mv;
public String getLoginStatus(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
throws Exception{
String str1 = paramHttpServletRequest.getParameter("user");
String str2 = paramHttpServletRequest.getParameter("password");
String s="";
System.out.println("---node"+str1);
System.out.println("---node"+str2);
if(str1.equals("admin") && str2.equals("admin")){
s="success";
}else{
s="failure";
}
return s;
}
这就是我从我的观点发出 ajax 请求的方式:
doLoginClicked : function() {
console.log("button pressed this time");
var name = this.view.getUsername();
var pass = this.view.getPassword();
console.log(name);
console.log(pass);
Ext.Ajax.request({
url: 'login/getLoginStatus.action',
method:'post',
params: {
user: name,
password: pass
}
,
success: function(response) {
console.log(response);
if (response=="success") {
// login.close();
} else {
console.log("inside failure");
Ext.Msg.show({
title:'Fail!',
msg: response,
icon: Ext.Msg.ERROR,
buttons: Ext.Msg.OK
});
}
},
failure: function(response) {
console.log("inside failure");
Ext.Msg.show({
title:'Error!',
msg: response,
icon: Ext.Msg.ERROR,
buttons: Ext.Msg.OK
});
}
});
}
它确实在控制台中显示了来自servlet的用户名和密码,但是我无法接受来自servlet的"成功"响应并采取相应的行动。以下是浏览器控制台中显示的响应:
Object {request: Object, requestId: 1, status: 200, statusText: "OK", responseText: ""…}getAllResponseHeaders: () {arguments: nullcaller: nulllength: 0name: ""prototype: response.getAllResponseHeadersconstructor: () {arguments: nullcaller: nulllength: 0name: ""prototype: response.getAllResponseHeaders__proto__: Empty() {}<function scope>__proto__: Object__proto__: Empty() {}<function scope>getResponseHeader: (header) {request: Objectasync: truebinary: falseheaders: Objectid: 1options: Object__proto__: ObjectrequestId: 1responseText: ""responseXML: nullstatus: 200statusText: "OK"__proto__: Object
有没有办法让我在从 servlet 返回"成功"时显示主页?
success: function(response)
上面代码行中的response
是一个对象。您将不得不更深入地了解您的对象,例如,response.status == '200'
或response.responseText == "success"
.
由于您没有给出您得到的确切响应,我将无法提供确切的代码,但这就是问题所在。
相关文章:
- 如何在JavaScript中将字符串转换为函数引用
- jQuery中是否内置了任何字符串格式化函数
- 尽管链接成功并已成功下载,但未找到NPM模块
- Javascript,有没有一种方法可以将数组写成没有逗号或空格的单个文本字符串
- ng打开空字符串
- 正则表达式在字符串中找到base64
- JavaScript 相等操作对单引号字符串和数字都成功
- 如何编写一个测试来验证函数是否已成功将字符串列表(在数组中指定)打印到屏幕上
- 数组中的字符串显示为未定义,尽管在几行之前成功.log控制台
- 使用字符串回复以在 JSON 成功时发挥作用
- 如何在ajax成功调用的html表中显示字符串数据
- 如何将字符串数据从ajax成功转换为javascript数据
- 当用于ajax调用webservice的数据类型为json "时,如何将成功函数的结果与字符串进行比较
- 回调成功后,不能将字符串推入数组
- 访问字符串存储在一个ViewBag ajax成功
- Ajax 成功使用 html 字符串作为 url 值
- 想要在使用 laravel(或常规 PHP)成功时将字符串从 PHP 返回给 AJAX
- 处理通过 ajax 调用从 servlet 返回的“成功”字符串
- Jquery ajax成功响应是字符串而不是javascript对象
- 如何从AJAX成功函数解析这个json字符串?