我想在 ajax 调用中发送布尔结果。
Ajax 调用
function myMethod() {
$.ajax({
type : "GET",
url : myurl
dataType : "json",
contentType: "application/json",
crossDomain: true,
success : function(data) {
alert("success :"+data);
},
error : function(data) {
alert("Fialed to get the data");
}
});
}Run Code Online (Sandbox Code Playgroud)
我想从中发送布尔结果的控制器方法。
@RequestMapping(value = "/myMethod", method = RequestMethod.GET)
@ResponseBody
public boolean myMethod(empId) {
flag = false;
try {
if (empId != null)
newName = Employee.getName(empId);
else
newName = Employee.getName();
} catch (Exception e1) {
flag = true;
System.out.println("flag :" + flag);
e1.printStackTrace();
}
return flag;
}Run Code Online (Sandbox Code Playgroud)
我想将布尔标志结果发送到 ajax 调用。我怎么寄。不介意逻辑.. 我只想知道如何将布尔结果发送到 ajax 调用。请帮忙 。
Ajax 使用 HTTP,它是一种文本协议,没有布尔值的概念。但是,您可以返回字符串“1”或“0”来表示您的布尔值。
然后,在您的“成功”回调中:
success : function ( data ) {
if ( data * 1 ) {
// true result
} else {
// false result
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4802 次 |
| 最近记录: |