-1

enter image description hereenter image description hereenter image description hereenter image description hereI am posting a value on a modal dialog box and then some database operations. Now I am returning a value through

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

Is this a right way? All the database operations are performed correctly but console.log(result) does not show anything on the calling script. Something's wrong with the couple of lines above. It would be very helpful if somebody points out the error.

 <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(); 
}

?>  

And my browser tool shows,

Loading failed for the <script> with source “http://localhost/project/js/compatibility.js”.
studyChapterpdf.php:54
Use of captureEvents() is deprecated. To upgrade your code, use the DOM 2 addEventListener() method. For more help http://developer.mozilla.org/en/docs/DOM:element.addEventListener
studyChapterpdf.php:240:36
ReferenceError: fakewaffle is not defined[Learn More]
studyChapterpdf.php:492:3
Warning: Setting up fake worker.
pdf.js:1489:5
progress 
Object { loaded: 131072, total: 551963 }
bootstrap-pdf-viewer.js:563:9
progress 
Object { loaded: 551963, total: 551963 }
bootstrap-pdf-viewer.js:563:9
page=1 - getOperatorList: time=522ms, len=755
Ansh
  • 269
  • 2
  • 15

1 Answers1

0

Found out the reason for it. There was an uncommented line left in one of the included files. So, the response was having the whole commented line as well as the actual return status==active. Fixed it. Thanks everyone for guiding.

Ansh
  • 269
  • 2
  • 15