0

In this code, OTPVerficationHTML() function having condition that data.rval == 2, where it should redirect to signin page and display the message in that page only

var flag = 0;
   $("#successPrimary").on('click', function(e) {
     e.preventDefault()
     user_name = $('#Login_UserName').val();
     password = $('#Login_Password').val();
     captcha = $('#Login_captcha').val();

     var PostData = {};
     PostData['put'] = true;
     PostData['form_login_username'] = user_name;
     PostData['form_login_password'] = password;
     PostData['form_login_captcha'] = captcha;

     Application.Post("/ajax/ajax_login", PostData, function(data){
        if(data.rval == 1){
          window.location = "/offerletter/index";
          Application.PageAlertBox.Show('Sucess', ['Login Successfully.']);
        }else if(data.rval == 2){
          OTPVerficationHTML()
          Application.PageAlertBox.Show('info', ['Enter OTP to Verify.']);
        }else{
          Application.PageAlertBox.Show('error',[data.Message]);
        }
      });
   });

   var OTPVerficationHTML = function () {
     initial_html = $('#otpfromlogin').html();
     $('#otpfromlogin').empty();
     $('#buttons').empty();
     $('#otpfromlogin').append(final_html);
     $('#Login_UserName').val(user_name);
     $('#Login_UserName').attr('readonly', 'true');
     $('#Login_UserName').focus();
   }

   $('#otpfromlogin').on('click', '#otp-verify', function(e) {
      e.preventDefault()
      otp = $('#form_otp').val();
       var PostData = {};
       PostData['put'] = true;
       PostData['form_login_otp'] = otp;

     Application.Post("/ajax/ajax_loginwithotp", PostData, function(data) {
        if(data.rval == 1) {
            window.location = "/offerletter/index";
            Application.PageAlertBox.Show('Sucess', ['Successfully Loggedin.']);
        } else if(data.rval == 2) {
            window.location = "/signin";
            Application.PageAlertBox.Show('info', ['OTP is Expired, Pleasem login with new OTP.']);
        } else if(data.rval == -4) {
            Application.PageAlertBox.Show('error', ['OTP is Invalid. Please Enter correct OTP.']);
        } else {
            Application.PageAlertBox.Show('error', [data.Message]);
        }
      });
   });

It is not displaying the message on signin page. I don't know how to deal with this kind of situation.

2 Answers2

0

If the redirection is working fine, you can change the below code:

window.location = "/signin";

to

window.location = "/signin?q=1";

And in your signin page, you can receive this using $_POST['q']. Based on this value, you can perform next set of activities in your signin page.

Milan Chheda
  • 8,009
  • 3
  • 19
  • 35
0

There are couple of ways doing this using jquery:

Window.loaction Will return the url of the current page. when assigned, changes the url of the page to the one assigned and shows it.

window.location = "/signin";

As the above example

Window.location.replace

Navigates to the desired url, without adding record to history.

window.location.replace("http://someaddress");

Window.location.assign

Navigates to the desired url, adding record to history.

window.location.assign("http://someaddress");

Window.location.href

simulating user click.

window.location.href = "/signin";

There is a Discussion Here about whether .location.href is of better use over .location if you are interested.

As the accepted answer stated, get the data using $_POST['q'].

Barr J
  • 10,104
  • 1
  • 27
  • 44