javascript - ajax background jumps to other pages and reports an error
扔个三星炸死你
扔个三星炸死你 2017-06-20 10:05:46
0
3
840

After ajax is executed, it jumps to background processing, but after processing, it jumps to other pages.

ajax:

$(".get-code").click(function(){        
    var user_number=$("input[name=user_number]").val();       
       alert(user_number);       
        $.ajax({type : "post",
            url : "user/validate",
            dataType : "json",
            data : {"phone" : user_number},
            success : function(data) {                                
            }
    
        });
       
   });

Button

 <button class="get-code">测试</button>

Backstage

@ResponseBody
@RequestMapping("/validate")
public Object validate(HttpSession session,String phone){
    Integer result1=(int)((Math.random()*9+1)*100000);
    String str=Integer.toString(result1, 10);
    String result=    str;    /*Sampler.samlerInfo(phone, null);*/
    System.out.println("随机数为:"+result);
    session.setAttribute("result", result+"");
    return null;
}

The control has output, indicating that it has come in,

In the end it jumped to other pages

The console also reported an error

扔个三星炸死你
扔个三星炸死你

reply all(3)
代言

After a brief look, the random numbers in your background have been printed, indicating that the Controller layer has been executed. Since you used @ResponseBody, why not just return your random number, result! Secondly, according to your answer, it jumps to another page after processing. This question should not jump, because after successfully requesting the back-end data, you should get the data you want, that is, the result in the ajax success. In fact, nothing is executed in your success! Personal understanding^~^

phpcn_u1582

Thank you for your answers. Since it is an SVN management project, my colleague accidentally deleted the </form> of a form on the same page yesterday, which caused the problem

我想大声告诉你

Why do you put the generated verification code in the session? Isn’t it enough to directly return the data to the ajax method? The success method in ajax will receive the return data.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template