ScottC
ScottC

Reputation: 462

unwanted newline character from Jquery ajax POST

Here is the jquery

$("#accountCheck").keyup(function(){

    $.post('accountEmailCheck.php',{value:$(this).val()},function(data){
        $("#emailCheck").val(data);
    });

     $.post('emailEICheck.php',{value:$(this).val()},function(data){

        if (data=='Yes'){ 

                            $("#autoEmail").prop("checked",true);
                        }else{ 

                            $("#autoEmail").prop("checked",false);
                        }
    });

Here is the PHP code

<?php

include 'sqlconn.php'; //just my sql connection strings

$strResult='';

$getEmailStatus = odbc_exec($live, "SELECT * FROM Accounts WHERE Account = '".$_POST['value']."'");
while(odbc_fetch_array($getEmailStatus)){

$strResult = odbc_result($getEmailStatus,'mailEI');

}

echo trim($strResult);

?>

the 'Yes' that comes back has a newline character at the end (the chrome dev tools shows it as like an enter symbol or return) even after I added the trim to the php...

Upvotes: 0

Views: 689

Answers (1)

Musa
Musa

Reputation: 97707

Remove the ?> at the end of your php file.
If you're not going to have any output after the code logic you should not have the ?> end tag because it could cause unintended whitespace to be outputted that may be after the ?>.

Upvotes: 4

Related Questions