Link to home
Start Free TrialLog in
Avatar of RationalRabbit
RationalRabbit

asked on

Server-side Query Fails To Find Records When Data Sent From Chrome on Android 10 (jQuery AJAX)

What is happening here makes no sense that I can see, as it is happening server side, I've verified that the values are being received, and it is only happening in Chrome and Adfroid 10.
I've tested this code on 3 other phones, with Android 2, 6, and 8. a Tablet (8), and a PC. Works fine on all of these devices.

My AJAX routine is quite simple:
$.ajax(
{
   type: 'post',
   data: {EmailBOL: EmailBOL, Test: 'testing'},
   url: 'scripts/BOLStorage.php',
   dataType: 'HTML',
   success: function(response)
   {
      $('#MWContent').html(response);
   },
   error: function(jqxhr, status, exception)
   {
      console.log('jqxhr:', jqxhr);
      console.log('status:', status);
      console.log('Exception:', exception);
   }
});

Open in new window


I've put echos from beginning to end of the code, bypassed the error checks, simplified the PDO code, and the results are always the same in all devices - all work except the Android 10 device when sent from a Chrome-based browser. Using that device, in combination with a Chrome-based browser, and even though the value of EmailBOL is received by the server and maintains its value, it finds no records. The server is http (not https), but I don't see how that would matter to the query. It's got the data, which is simply the email address.

My minimized code server-side looks like this:
<?php
session_start();
#====================================================
include("../include/dbconnect.php");
$Charset = 'utf8';
$DSN = "mysql:host=$HOST;dbname=$DBName;charset=$Charset";
$Options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false,);
try
{
   $pdo = new PDO($DSN, $USER, $PASSWORD, $Options);
}
catch (PDOException $e)
{
   $LogData = "\n".date('Y-m-d H:i').' '.$_SESSION[PageName].' '.$e->getMessage().' '.(int)$e->getCode();
   error_log($LogData, 3, "error.log");
   $Error[] = "Server Connect Error! [1]";
}
#====================================================
$EmailBOL = $_REQUEST['EmailBOL'];
if(!empty($EmailBOL))
{
    $query = "SELECT count(*) FROM BOLStore WHERE Email = '$EmailBOL'";
   try{$stmt = $pdo->query($query);}
   catch (PDOException $e)
   {
      $ErrorMsg = "DataBase Error! [1]";
      $Error[] = $ErrorMsg;
      $LogData = "\n".date('Y-m-d H:i').' '.$_SESSION[PageName].' '.$ErrorMsg.' '.$e->getMessage().' '.(int)$e->getCode();
      error_log($LogData, 3, "error.log");
   }
   $Count = $stmt->fetchColumn();
   echo($Count." Records Found<br />");
   echo("Email: ".$EmailBOL."<br />");
   echo("Test: ".$_REQUEST[Test]."<br />");
   if($Count > 0)
   {
      $stmt = $pdo->query("SELECT * FROM BOLStore WHERE Email = '$EmailBOL' ORDER BY DocName");
      echo('
      <h4 style="margin-bottom:3px;">Select a saved form:</h4>
      <table style="width:100%;">
      <tr class="LightGray"><th></th><th>Doc #</th><th>Doc Name</th><th>Consignee</th><th></th></tr>
      ');
      $BGColor="#E9E9E9";
      while ($Row = $stmt->fetch())
      {
         $BGColor = $BGColor=="#E9E9E9" ? "#FFFFFF" : "#E9E9E9";
         echo('
         <tr style="background:' . $BGColor . '"><td><a class="ViewClick" href="'.$HrefRoot.'blformfill.php?i='.$Row[ID].'&DocName='.$Row[DocName].'&Email='.$Row[Email].'&View=1" target="_parent">View/Edit</a></td><td>'.$Row[ID].'</td><td>'.$Row[DocName].'</td><td>'.$Row[Consignee].'</td><td><a href="'.$_SERVER[PHP_SELF].'?i='.$Row[ID].'&del=1">Delete</a></td></tr>
         ');
      }
      echo('
      </table>');
   }
   else
   {
      echo('<h4>No previous documents found for '.$EmailBOL.'</h4>');
   }
}
else
{
   echo('Nothing found for this email address');
}
?>

Open in new window

 

The return is "No previous documents found for {whatever email address is sent}"
No matter how I do this query, the number of rows always comes up zero if the originating device is Android 10 on a Chrome (Or Brave or Samsung Internet) browser.
Works on all other browsers on Android 10.
Works with all browsers, including Chrome-based in versions other than 10.

I realize how illogical this sounds, but that is what is happening. I've spent hours testing this. I'll mention again, I've verified that, from beginning to the end of the code. $EmailBOL and $Test hold and can return their values.
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RationalRabbit
RationalRabbit

ASKER

"you think it's a browser issue, let's go :) "
Yeah, I know :)
Well, of course, it is the obvious. I thought I had tested for extra characters early on, and saw none, so dismissed that. Your suggestion made it embarrassingly clear. Sure enough, a simple trim solved the problem.
I have seen a number of people having issues with both Android 9 & 10 with Chrome and jQuery. Makes me wonder if this is not the problem with most of these issues. It appears that, when using that browser/OS combination with AJAX, an extra character is being inserted at the beginning of the string. (Or, it may be, the others are trimming the string and the extra character is hsppening elsewhere.)
Aside from that, if you have comments on my serverside code, I'm all ears.
Confirmed. Chrome, on Android 10, is inserting an extra character at the beginning of the string. This is happening before the string is ever sent to the server. Here is what I am doing:
<input class="TextBox" type="text" id="EmailBOL_Local" name="EmailBOL" value="" size="18" maxlength="100" />
<a class="lightview GoTo" id="StorageList">Go</a>

Open in new window


<script>
   $('#StorageList').on('click', function()
   {
      var EmailBOL = $('#EmailBOL_Local').val();
      ShowArchive(EmailBOL);
   });


   function ShowArchive(EmailBOL)
   {
      // inserting alert("X"+EmailBOL+"X") here shows "X EmailBOLX in Chrome, Android 10, XEmailBOLX in others.
      $.ajax(
      {
            type: 'post',
            data: {EmailBOL: EmailBOL'},
            url: 'scripts/BOLStorage.php',
           // etc...
      }
   }
</script>

Open in new window


try removing the value attribute

<input class="TextBox" type="text" id="EmailBOL_Local" name="EmailBOL" size="18" maxlength="100" /> <a class="lightview GoTo" id="StorageList">Go</a>
Makes no difference. Still an extra character.