简体   繁体   中英

Sign-in code not working in Internet Explorer but yes in Chrome and Firefox

I hope this isn't too much of a tedious question... I am working on this code that someone else wrote. The problem simply is that it works fine on Chrome and Firefox but not on Internet Explorer. What happens is when clicking on the submit the page simply reloads and starts afresh. I have no clue why? Can anyone help?

Here is the HTML: It is essentially two fields that ask for phone number and pin code...

<form name="form1" id="form1" onSubmit="get_client_data(); return false;" method="post" >
  <input type="hidden" name="random_1" id="random_1" value="<?=$session['random_1']?>" /> 
  <h2>ENTER THE NUMBER YOU’D LIKE TO REFILL</h2>
  <input placeholder="ENTER YOUR PHONE NUMBER:" name="phone_number" id="phone_number" type="text" class="form_input" onBlur="convert_phone(this.value,'phone_number');" />

  <h2>ENTER YOUR PIN</h2>
  <input placeholder="ENTER YOUR PIN CODE:" name="pin_id" id="pin_id" type="text" class="form_input" onBlur="check_validity(this.value, 'pin_id');" /><br>

  <input name="" type="submit" value="GO" class="right button go" id="step_1" />
  </form>

The onSubmit sends to the following javascript function: (this uses ajax to determine if the number and pin match and if they do - it will enable other parts of the HTML (not given here))

function get_client_data(){

  var pin_id =  $('#pin_id').val(); 
  var phone_number = $('#phone_number').val();
  var random_1 =  $('#random_1').val();  

  $.ajax({
    type: "POST",
    url: "front_end_functions.php",
    data: "phone_number="+phone_number+"&plan="+plan+"&pin_id="+pin_id+"&random_1="+random_1+"&function=get_client_data",
    dataType: 'json',
    success: function(msg){  

    if(msg == 'error') {  
      alert('error'); 
      return false;             
   } else if(msg == 'error2') {
     alert('error'); 
      return false;
   } else {

    $('#div_1').addClass('deselect');
    $('#div_2').removeClass('deselect');   

    $('#phone_number').attr('disabled','disabled');
    $('#pin_id').attr('disabled','disabled');
    $('#step_1').attr('disabled','disabled');       

    $('#phone').removeAttr('disabled');
    $('#carrier').removeAttr('disabled');
    $('#plan').removeAttr('disabled');
    $('#step_2').removeAttr('disabled');   

    $('#phone').val(msg[1]);
    $('#carrier').val(msg[2]);
    $('#plan').val(msg[3]);  
   }
 }
 });
}

The function that Ajax sends to looks like this (as you can see I am using PDO - does that cause problems?):

if($_REQUEST['function'] == 'get_client_data')  {

$random_1 = $_REQUEST['random_1'];
$ip = getenv('HTTP_CLIENT_IP')?:
getenv('HTTP_X_FORWARDED_FOR')?:
getenv('HTTP_X_FORWARDED')?:
getenv('HTTP_FORWARDED_FOR')?:
getenv('HTTP_FORWARDED')?:
getenv('REMOTE_ADDR');

$query = $db->prepare("SELECT * FROM sessions WHERE id = ?");
$query->execute(array($ip));
$session = $query->fetch();

if($session['random_1'] == $random_1) {

  $phone_number = $_REQUEST['phone_number'];
  $pin_id = $_REQUEST['pin_id'];

  $sql = "SELECT c.cid, cp.phone, cr.carrier_name, p.plan_name ,cp.carrier as cr_id,cp.plan as p_id
          FROM clients c, client_phones cp , carriers cr, plans p
          WHERE cp.phone = ? 
          AND cp.client_id = ?
          AND cp.deleted = 0
          AND c.cid = cp.client_id 
          AND c.status = 'a'
          AND cr.carrier_id = cp.carrier
          AND p.plan_id = cp.plan";

  $query = $db->prepare($sql);
  $query->execute(array($phone_number, $pin_id));
  $result = $query->fetch();
  if(!empty($result)){
        $_SESSION['client'] = $result;
        echo json_encode($result);
  }else{
    echo json_encode('error'); 
    }
}else{
  echo json_encode('error2');
}     
}   

Thanks!

Yep - worked it out, Using the debugger on IE (sorry for not doing that earlier) it says that 'plan' in the data part of the ajax code is undefined. So that caused the error. Interesting that Chrome and Firefox don't have that problem...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM