drqn5418 2018-05-21 10:26
浏览 386

成功的ajax返回时,模态框不会关闭

I have a modal window that pops up whenever a screen is ideal for 3 minutes. It asks for a PIN to be entered and there is a Continue button on that to be clicked after the PIN is entered in it. On using this Continue button, an insert is made in a database table. Now my problem here is on entering the PIN and clicking on Continue button, the modal does not hides or closes itself. Although the database insertion is done but the modal does not hides. What can be possibly going wrong in this. Any suggestion will be highly helpful. My code,

 <div class="modal fade" id="myModal"  role="dialog" data-backdrop="static" data-keyboard="false">

    <div class="modal-dialog">

      <!-- Modal content-->

<form name="frmActive" id="frmActive" action="" method="post">      
      <div class="modal-content" style="height:250px;">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Ideal Time activation</h4>
        </div>
        <div class="modal-body">
          <p>Please enter activation <b>PIN</b><font color="red">*</font><br>

          <p id="msg" style="color:#F00;"></p>
          <input type="password" name="pin" id="pin" value="" maxlength="4"  onKeyUp="checkNumber(this)"  class="form-control" placeholder="Enter Pin">
          <input type="hidden" id="inactiveTime">
          <p style="font-size:11px"><b><font color="red">*</font><font color="grey"><b>PIN</b><i> is mentioned in your welcome email.</font></i></b></p><br>

        </div>
        <div class="modal-footer">

       <button type="button" id="btnSubmit" name="submit" value="submit" class="btn btn-success"><i class="glyphicon glyphicon-floppy-disk"></i> Continue</button> 
       <input type="hidden" id="module_id" value="<?php echo $moduleId ; ?>">
       <input type="hidden" id="chapter_id" value="<?php echo $chapterId ; ?>">

        </div>
      </div>
</form>      
   </div>
  </div>
jQuery("#btnSubmit").on("click", function(){

    var pin             =   jQuery("#pin").val();
    var chapter_id      =   jQuery("#chapter_id").val();
    var module_id       =   jQuery("#module_id").val();
    var nowDate         =   jQuery.now();
    var inactiveTime    =   jQuery("#inactiveTime").val();
    var seconds         =   (nowDate - inactiveTime) / 1000;

    var formData    =   new FormData();
        formData.append("pin", pin);
        formData.append("seconds", seconds);
        formData.append("module_id", module_id);
        formData.append("chapter_id", chapter_id);

      $.ajax({
        url: "processActivation.php",
        type: "POST",
        data: formData,
        processData: false,
        contentType: false,

        success: function(result){          


           if(result['status'] == 'active')

            {

                jQuery('#myModal').modal('hide');
            }
            else
            {

                $("#msg").html(result) ;

            }

        }
      });

});

And processActivation.php,

<?php
$uid        =   $_SESSION['session_user_id'];
$dobCheck   =   $db->idToField("tbl_user", "dob", $uid);
$dob        =   explode("-", $dobCheck);

$pin            =   $_REQUEST['pin'];
$moduleId       =   $_REQUEST['module_id'];
$chapterId      =   $_REQUEST['chapter_id'];
$time_taken     =   $_REQUEST['seconds'];
$created        =   date("Y-m-d h:i:s");
if($pin != $dob[0])
{

    echo "Please enter valid PIN."; die;
}
else
{

    $dataactivation =   array("user_id"=>$uid, "module_id"=>$moduleId, "chapter_id"=>$chapterId,"time_taken"=>$time_taken, "created"=>$created);
    $db->query_insert("tbl_activation", $dataactivation);   


  header('Content-Type: application/json', true, 200); 
  echo json_encode(array('status' => 'active')); 
  exit(); 
}

?>  

I want to know if

header('Content-Type: application/json', true, 200); 
      echo json_encode(array('status' => 'active')); 
      exit();

is the right way?? Because all of the above operations are being performed correctly and upon that console.log(result) does not shows up anything. Something wrong with the above couple of lines. Very helpful if somebody points out the error in this.

  • 写回答

3条回答 默认 最新

  • dongmie3526 2018-05-21 10:28
    关注

    A quick fix maybe, instead of doing
    echo json_encode(array('status' => 'active')); and if(result['status'] == 'active')
    do
    echo "active"; and if(result == 'active')

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类