Forum Moderators: coopster

Message Too Old, No Replies

PHP response returns a New Line to Ajax request

PHP and AJAX

         

jayapalchandran

2:45 pm on Sep 27, 2007 (gmt 0)

10+ Year Member



My PHP page responds to an AJAX request like the following

<?php
if( $_POST["username"] == "samy" )
echo "yes"
else
echo "no"
?>

in my javascript code i am checking the response text for yes or no like the following

if(ajax.responseText=="yes")
alert("Welcome samy");
else
alert("invalid username");

the problem is before the letter y in yes a new line is inserted...
why it is so... is there any method to stop it while sending the response back from the php page... it is fine to do manual removal or split of new line but i want to know why it is a case and what has to be done...?

ayushchd

2:50 pm on Sep 27, 2007 (gmt 0)

10+ Year Member



Are you calling the response in a div?

What is ur original php code (the one being requested by AJAX)

jayapalchandran

8:04 pm on Sep 27, 2007 (gmt 0)

10+ Year Member



jaz = new ActiveXObject("Microsoft.XMLHTTP");
if(jaz==null){alert("Cant Create Ajax Connection");return;}
jaz.onreadystatechange=retpass;
param="pasi=" + passvalue.value;
jaz.open("POST","ListAuth.php",true);
jaz.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
jaz.send(param);

ayushchd

7:26 am on Sep 28, 2007 (gmt 0)

10+ Year Member



The PHP Code which is responding to the request....the one which is echoing yes/no

are u getting the response in div?