weixin_33696106
weixin_33696106
2016-12-07 18:37
采纳率: 0%
浏览 19

流不在$ .ajax内部

When i click on login button. Below function will be called. Execution flow is going till $.ajax but its not going inside $.ajax. Can anyone please help me on this.

$('#login').click(function() {

    var contextroot = "/services/";

    var userName = $('#userName').val();
    var password = $('#password').val();
    alert("insid ::: ");    
    $.ajax({
        url: contextroot+"login",
        dataType: 'json',
        type: 'GET',
        contentType: 'application/json',
        data: {
            userName:userName,
            password:password
        },

        success: function(data){
            sessionStorage.setItem("userName", "sharana");
            window.location.href = '/admin/index.html';
            return false;
        }
    });



});

图片转代码服务由CSDN问答提供 功能建议

                    

当我单击登录按钮时。 下面的函数将被调用。 执行流将一直到$ .ajax,但不会在$ .ajax内部。 谁能帮我这个忙。

  $('#login')。click(function(){

     var contextroot =“ / services /”;

     var userName = $('#userName')。val();
     var password = $('#password')。val();
     alert(“ insid :::”);
     $ .ajax({
         url:contextroot +“登录”,
         dataType:'json',
         输入:“ GET”,
         contentType:“ application / json”,
         数据:{
             userName:用户名,
             密码:password
         },

         成功:功能(数据){
             sessionStorage.setItem(“ userName”,“ sharana”);
             window.location.href ='/admin/index.html';
             返回false;
         }
     });



 });
  
     
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • weixin_33704234
    weixin_33704234 2016-12-07 18:44

    Make available entire contextRoot in single variable as below

    $('#login').click(function() {
    
      var contextroot = '/services/login';
    
      var userName = $('#userName').val();
      var password = $('#password').val();
      alert("insid ::: ");    
      $.ajax({
        url: contextroot,
        dataType: 'json',
      ....
      ...
    
    点赞 评论

相关推荐