jquery - PHP Ajax calls is not getting an existing JSON array of result when AES encryption is used in database -


edit #2

i added var_dump($res) , can see there array when typing something:

enter image description here

but th ehtml table not changing @ add result. error in javascript.

end

i have page can search long list of patients using jquery events ajax calls php server.

here jquery/ajax function sends variable called searchtxt server:

var searchfunction = function(){ var searchtxt = $("#searchtxt").val(); searchtxt = $.trim(searchtxt); //console.log(searchtxt); $.ajax({     url: '../php/searchpatient.php',     type: 'post',     data: {searchtxt: searchtxt},     datatype: 'json',      success:function(resp)     {         //append data         $("#patient_table tr").fadeout(400);         $("#after_tr").before("<tr class='bg-info'><th>id</th><th>name</th><th>date of birth</th><th>phone</th><th>status</th><th>change status</th><th colspan='5' style='text-align:center'>actions</th></tr>");         $.each( resp, function(key, result)         {             var pid = result['patient_id'];             var profilebtn = "<a id='profilebtn'><span class='badge badge badge-info' style='background-color: #0090ff'>patient profile</span></a>"             $("#after_tr").after("<tr id="+result['patient_id']+"><td>"+result['patient_id']+"</td><td>"+result['patient_name_en']+"</td><td>"                 +result['dob']+"</td><td>"+result['patient_phone']+"</td><td>"                 +result['patient_status']+"</td><td><select style='color: #0090ff; ' class='form-control select patient_status' name='patient_status'><option value='select'>select</option><option value='active'>active</option><option value='deceased'>deceased</option><option value='discharged'>discharged</option><option value='defaulter'>defaulter</option></select><td>"+profilebtn+"</td>");              //if visit button clicked             $("#patient_table #profilebtn").on('click', function(){                 var id = $(this).closest('tr').attr('id');                 window.location.href = "patient_profile_page.php?pid="+id;             })             $(document).on('change', '.patient_status', function() {                 var $select = $(this);                 var $tr = $select.closest('tr');                 var pid = $tr.attr('id');                 var $status = $tr.children('td.change_status');                 var current_status = $status.text();                 var new_status = $select.val();                 console.log(new_status);                 if (current_status == new_status) {                   alert("the status selected same!");                 }                  else {                   //if (confirm("are sure want change status of patient ?")) {                      //console.log(pid + " " + new_status);                     $.ajax({                       url: '../php/changestatus.php',                       type: 'post',                       datatype: 'text',                       data: { pid: pid, new_status: new_status },                       success: function(resp) {                         if(resp=="updated")                         {                             $status.text(new_status);                             //console.log(resp);                         }                       },                       error: function(resp) {}                     });                   //}                 }               });         });     },     error:function(resp)     {         console.log(resp);     } }); } 

and here events @ same file:

$(document).ready(function() {     $("#searchtxt").on('keyup', searchfunction);     $("#searchbtn").on('click', searchfunction);     $("#searchbtn").on('change', searchfunction); }); 

the php script searchpatient.php:

$res = array(); $cid = $_session['clinic_id']; $searchtxt = '%'.$_post['searchtxt'].'%';  $searchpatient = "select patient_id, aes_decrypt(patient_name_en, 'key1') patient_name_en, patient_name_ar, dob, patient_phone, patient_status                   patient clinic_id = :cid , patient_id :searchtxt                   or aes_decrypt(patient_name_en, 'key1') :searchtxt or dob :searchtxt or aes_decrypt(patient_phone, 'key1') :searchtxt or aes_decrypt(patient_name_ar, 'key1') :searchtxt"; $execsearchpatient = $conn->prepare($searchpatient); $execsearchpatient->bindvalue(':cid', $cid); $execsearchpatient->bindvalue(':searchtxt', $searchtxt); $execsearchpatient->execute();  $execsearchpatientresult = $execsearchpatient->fetchall();  $i = 0; foreach($execsearchpatientresult $result) {     $res[$i] = $result;     $i++; }  echo json_encode($res); 

i changed , add try{} catch{} catch errors:

try {     $res = array();     $cid = $_session['clinic_id'];     $searchtxt = '%'.$_post['searchtxt'].'%';      $searchpatient = "select patient_id, aes_decrypt(patient_name_en, 'key1') patient_name_en, patient_name_ar, dob, patient_phone, patient_status                       patient clinic_id = :cid , patient_id :searchtxt                       or aes_decrypt(patient_name_en, 'key1') :searchtxt or dob :searchtxt or aes_decrypt(patient_phone, 'key1') :searchtxt or aes_decrypt(patient_name_ar, 'key1') :searchtxt";     $execsearchpatient = $conn->prepare($searchpatient);     $execsearchpatient->bindvalue(':cid', $cid);     $execsearchpatient->bindvalue(':searchtxt', $searchtxt);     $execsearchpatient->execute();      $execsearchpatientresult = $execsearchpatient->fetchall();      $i = 0;     foreach($execsearchpatientresult $result)     {         $res[$i] = $result;         $i++;     }      echo json_encode($res); } catch(pdoexception $e) {     echo $e->getmessage(); } 

here current 2 patient list:

enter image description here

now if typed inside text box 0361 in database part of id, can't see result:

enter image description here

and @ console, there no error have this:

object {readystate: 4, getresponseheader: function, getallresponseheaders: function, setrequestheader: function, overridemimetype: function…}

p.s.

i tested query in mysql workbench , returning results.

there can multiple causes this, did try log function on backend side , see data send backend? , send back? had same problems 1 solved by:

1.adding event.preventdefault();

  1. and other solved fix chrome jquery ajax failing, not cross-domain issue

my recommendation try generate request on postman , see returned result , log happens on backend , trying return.

hope helps bit!


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -