0

Previously, i was using PHP 5.6.3 with sqlsrv on IIS 7.5 on windows 7 and PHP was working fine with ajax success. I upgraded to Windows 10 and when i try to echo a string, a character is found attached to the string in ajax function. Please I want to know what is causing that.

PHP

    $params=array($_POST['uID']);
    $sql="SELECT * FROM users WHERE uID=?";
    $stmt=sqlsrv_query($conn,$sql,$params);
    if(!$stmt)
    {
      echo "1"; 
    }
    else
    {
        $row=sqlsrv_fetch_array($stmt);
        if($row>0)
        {
           echo "1";
        }
        else
        {
           echo "0";
        }
    }

AJAX

    var uID=$('#fUID').val();
    $.ajax(
    {
        type:"POST",
        url:"adminDB.php",
        data:"uID="+uID+"&action="+action,
        cache:true,
        success:function(msg)
        {
            alert(msg);
        }
    });

OUTPUT:

enter image description here

Jeff Puckett
  • 37,464
  • 17
  • 118
  • 167
Big Pee
  • 1
  • 2

3 Answers3

1

My guess will be that your adminDB.php file contains BOM at the beginning of the file.
If you will remove that from your PHP file (you can do this using notepad++ and some other text editors) you will be able to compare the strings the way you like.

Community
  • 1
  • 1
Dekel
  • 60,707
  • 10
  • 101
  • 129
0

Try setting the header to output json, since that's what jquery's ajax function expects by default:

header('Content-Type: application/json; charset=UTF-8');

You should do this before your echo statements.

inorganik
  • 24,255
  • 17
  • 90
  • 114
  • Please Sir, I am suspecting the problem may come from the PHP Configuration but have no ideas where to go and make that changes – Big Pee Jun 05 '16 at 21:18
0

After wondering my head over this issue...i finally got a way around it. I used json_encode() and was able to compare the string returned. I definitely know the problem is an issue between PHP and SQLSRV drivers in Windows 10 32bit.

$resp=array('message'=>'1');
echo json_encode($resp);
Big Pee
  • 1
  • 2