ajax请求成功但不执行success-function回调函数
今天在进行token返回测试的时候项目不完全还没有统一的返回格式,我用了String返回了token,
而在ajax中选择了dataType:'json'来接受
所以在success返回函数中一直没有执行下面的步骤,我加入了error进行测试,果然跳转了错误函数,判断为是返回设置类型的问题,将返回类型修改为text就正常执行了
当用户返回数据是字符串而不是集合的时候设置dataType为json就可能出现问题,所以尽量设置统一的数据返回格式,下面是我们的统一返回格式类。
package xxx;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Setter
@Getter
@ToString
public class ResponseParam {private int status = ResponseCodeEnum.SUCCESS.getCode ( );
private String message = ResponseCodeEnum.SUCCESS.getMsg ( );
private Object result;
private Object resParam;
public Object getResParam() {
return resParam;
}public void setResParam(Object resParam) {
this.resParam = resParam;
}public ResponseParam() {
}public ResponseParam(String message) {
this.message = message;
}public ResponseParam(int status, String message) {
this.status = status;
this.message = message;
}public ResponseParam(String message, Object result) {
this.message = message;
this.result = result;
}public ResponseParam(Object result) {
this.result = result;
}public ResponseParam(ResponseCodeEnum codeEnum) {
this.status = codeEnum.getCode ( );
this.message = codeEnum.getMsg ( );
}public int getStatus() {
return status;
}public void setStatus(int status) {
this.status = status;
}public String getMessage() {
return message;
}public void setMessage(String message) {
this.message = message;
}public Object getResult() {
return result;
}public void setResult(Object result) {
this.result = result;
}public String toJSONString() {
return JSON.toJSONString (this);
}
}