问题1:

使用ajax访问的后台,后台正常执行,并且正常返回数据,但是不能进入前台的ajax回调函数中

问题展示:

 问题解决:

最后发现是因为后台的方法并未加注解:@ResponseBody,导致方法不认识最后返回的是给ajax的data,而是以为要去找这个页面所以并未找到!!

 @RequestMapping("/queryAllDisease")
@ResponseBody
public PageInfo<Disease> queryAllDisease(String productId, ModelMap model, int pageNo , int pageSize){
Product product =new Product();
product.setProductId(productId);
Criteria criteria = getCurrentSession().createCriteria(Disease.class);
criteria.add(Restrictions.eq("product", product));
return diseaseService.findQuery(criteria, pageNo, pageSize);
}

同样的,如果Controller中的方法执行完成之后  不想返回前台,就此打住,则也需要加上@ResponseBody

因为即使方法返回值为void

spring也会按照前台请求过来的页面地址去找,找不到就会如下:

所以,在后台:【以下的代码依旧是  按照前台department/addPosition.htmls继续找下去,如果想在此打住,不要再去前台了,添加注解】

 @RequestMapping("addPosition")
public void addPosition(Position position){
position.setCreateDate(new Timestamp(System.currentTimeMillis()));
position.setUpdateDate(new Timestamp(System.currentTimeMillis()));
//操作人 未插入
positionService.save(position);
}

更改之后如下:

 @RequestMapping("addPosition")
@ResponseBody
public void addPosition(Position position){
position.setCreateDate(new Timestamp(System.currentTimeMillis()));
position.setUpdateDate(new Timestamp(System.currentTimeMillis()));
//操作人 未插入
positionService.save(position);
}

问题2:

在此基础上,又发现一种新的情况:

后台代码如下:

 @RequestMapping("verifyFormula")
@ResponseBody
public void verifyFormula(String formula){
InfixInToSuffix is = new InfixInToSuffix();
String a = null;
try {
if(is.userPattern(formula)){
a = is.toSuffix(formula);
}
} catch (Exception e) {
System.out.println("公式有问题");
}
}

或者:

 @RequestMapping("verifyFormula")
@ResponseBody
public String verifyFormula(String formula){
InfixInToSuffix is = new InfixInToSuffix();
String a = null;
try {
if(is.userPattern(formula)){
a = is.toSuffix(formula);
}
} catch (Exception e) {
System.out.println("公式有问题");
}
return a;
}

这两种情况,虽然前台js中使用ajax访问了后台,但是后台方法处理完

1.void没有返回值

2.虽然有返回值,但是String a = null;可能会直接将这个a返回,但是a初始化就是Null,也就是没有开辟实际的空间,这样也是返回不到ajax的回调函数中的!!!!!

多注意这两种情况!!

正确处理这种情况,应当:

     @RequestMapping("verifyFormula")
@ResponseBody
public String verifyFormula(String formula){
InfixInToSuffix is = new InfixInToSuffix();
String a = "";
try {
if(is.userPattern(formula)){
a = is.toSuffix(formula);
}
} catch (Exception e) {
System.out.println("公式有问题");
}
return a;
}

最起码的给String a = "";即可!!

问题3:

同样在controller处理完后,前后台都没有报错,但是也是没有进入ajax回调函数

后台错误代码展示:

 @RequestMapping(value = "boundWx" ,produces = "text/json;charset=UTF-8")
@ResponseBody
public String boundWx(String name,String password){
List<Member> members = new ArrayList<Member>();
Member member = memberService.findByUsername(name);
if(member == null){
member = memberService.findByMobile(name);
if(member == null){
members = memberService.findListByEmail(name);
}
}
if(members.size() > 0){
member = members.get(0);
}
if(member != null){
if(DigestUtils.md5Hex(password).equals(member.getPassword())){
return "wx/member/index.jhtml";
}else{
return "密码有误";
}
}else{
return "用户信息有误";
}
}

问题解决:

因为这个方法中 返回给前台后是有乱码出现的,所以加了:@RequestMapping(value = "boundWx" ,produces = "text/json;charset=UTF-8")

而问题就出在:此处的produces = "text/json;charset=UTF-8"与返回值的格式并不相符。

更改为如下的就可以正常返回了:

@RequestMapping(value = "boundWx" ,produces = "text/html;charset=UTF-8")

问题4:

新的同类型问题

ajax + springMVC后台处理完成跳转给前台的ajax的回调函数中,

表现:后台程序执行了三次,但是最后都不会返回到前台回调函数中,且前后台都不报错!

问题:请认真检查前台使用了ajax的是在哪个按钮的点击事件中,这个点击事件是否 return ; 请认真检查前台jsp中是否重复引用了jQuery等js文件导致后台会重复执行几次

问题5:

依旧是ajax + springMVC后台处理完成跳转给前台的ajax的回调函数中,

虽然前台返回状态是200,请求成功,但是始终不进入ajax的success回调方法。

问题:检查后台接口是不是返回的是null,也就是return null;

因为即使状态是200.但是只能代表前后台是联通的,但是不代表返回的参数是有值的,如果return null;那么回到前台以后,判断success字段值如果没有值,当然会进入error的回调函数,而不会进入success的回调函数。

【springMVC 后台跳转前台】1.使用ajax访问的后台,后台正常执行,返回数据,但是不能进入前台的ajax回调函数中 ----2.前后台都没有报错,不能进入ajax回调函数的更多相关文章

  1. vue调用组件,组件回调给data中的数组赋值,报错Invalid prop type check failed for prop value. Expecte

    报错信息: 代码信息:调用一个tree组件,选择一些信息 <componentsTree ref="typeTreeComponent" @treeCheck="t ...

  2. yum安装的时候报错,关于python的函数库

    我在执行yum -y install nc命令的时候出现如下报错 There was a problem importing one of the Python modulesrequired to ...

  3. Xcode报错Xcode导入runtime框架函数参数没有提示或Too many arguments to function call, expected 0, have 2错误

    前言:在引入<objc/runtime.h> 与 <objc/message.h> 后,调用objc_msgSend(),会报如下错误: 报错原因: 从Xcode6之后,苹果不 ...

  4. mysql 创建函数或者存储过程,定义变量报错

    报错的原因是因为在过程或者函数中存在分隔符 分号(:),而mysql中默认分隔符也是 :,这就导致存储过程分开了 在存储过程外面包一层 delimiter //   code  //就行了

  5. 解决VS2013报错fopen、sprintf等函数安全的问题

    VS2013中使用fopen.sprintf等函数是会出现安全问题: error C4996: 'fopen': This function or variable may be unsafe. Co ...

  6. ajax访问 aspx.cs后台

    --前台$.ajax({ type: "POST", contentType: "application/json", url: "WebForm2. ...

  7. 函数内部的函数中的this都是指向window

    刚看到一个问题关于this的, var name="the window"; var object={ name:"silence", packname:fun ...

  8. javascript函数中的实例对象、类对象、局部变量(局部函数)

    定义 function Person(national,age) { this.age = age; //实例对象,每个示例不同 Person.national = national; //类对象,所 ...

  9. 常规函数模块CALL in new task 报错

    使用START NEW TASK, 函数需要是远程调用模块. 错误:FUNCTION module  ' ZMMFM0021'  cannot be used for 'remote' CALLS. ...

随机推荐

  1. 破损的键盘(UVa 11988)

    s[] 数组用来保存原有的字符序列 nex[] 数组记录打印的下标顺序 C++11 代码如下: #include<iostream> #include<cstring> usi ...

  2. 集合栈计算机(UVa12096)

    题目具体描述见:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_prob ...

  3. Rookey.Frame之实体FluentValidation验证

    昨天给大家介绍了Rookey.Frame框架的实体设计,今天继续跟大家分享实体的FluentValidation验证,在Rookey.Frame框架中可以设置多种验证方式:FluentValidati ...

  4. USACO 6.3 Cowcycles

    CowcyclesOriginally by Don Gillies [International readers should note that some words are puns on co ...

  5. Bootstrap--响应式图片轮播

    <div class="row"> <div class="span12"> <section id="carousel ...

  6. Xposed模块开发教程

    转:http://vbill.github.io/2015/02/10/xposed-1/     http://blog.csdn.net/zhangmiaoping23/article/detai ...

  7. Oracle截取字符串和查找字符串

    oracle 截取字符(substr),检索字符位置(instr) case when then else end语句使用 收藏 常用函数:substr和instr 1.SUBSTR(string,s ...

  8. php中empty和isset函数

    函数使用格式 empty bool empty ( mixed $var ) 判断变量是否为空. isset bool isset ( mixed $var [ , mixed $... ] ) 判断 ...

  9. 远程连接mysql root账号报错:2003-can't connect to MYSQL serve

    1.远程连接Linux系统,登录数据库:mysql -uroot -p(密码) 2.修改root账号的设置: GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDE ...

  10. POJ - 3111 K Best 0-1分数规划 二分

    K Best Time Limit: 8000MS   Memory Limit: 65536K Total Submissions: 12812   Accepted: 3290 Case Time ...