View Full Version : Response Text Prepending \r\n
Dan06
05-08-2009, 11:10 PM
The ajax response text is prepending "\r\n" to every response. Is there a way to eliminate the added return and newline characters?
Thanks.
itsallkizza
05-08-2009, 11:23 PM
can you post the javascript code you have? and possibly the output of the ajaxed page, or a link to the ajaxed page?
Dan06
05-08-2009, 11:57 PM
can you post the javascript code you have? and possibly the output of the ajaxed page, or a link to the ajaxed page?
Here is the js :
var params = "userName=" + userName;
var url = "user.php"
Ajax.post(params, url, false);
var Ajax = {
post : function(params, url, async){
var XMLHttpRequestObj = false;
if (window.XMLHttpRequest){
XMLHttpRequestObj = new XMLHttpRequest();
} else if (window.ActiveXObject){
XMLHttpRequestObj = new ActiveXObject("Microsoft.XMLHttp");
}
if (XMLHttpRequestObj){
XMLHttpRequestObj.open("POST", url, async);
XMLHttpRequestObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
XMLHttpRequestObj.setRequestHeader("Content-length", params.length);
XMLHttpRequestObj.setRequestHeader("Connection", "close");
XMLHttpRequestObj.send(params);
if (async){
XMLHttpRequestObj.onreadystatechange = function(){
if (XMLHttpRequestObj.readyState == 4 && XMLHttpRequestObj.status == 200){
Ajax.saveResponse(XMLHttpRequestObj.responseText);
delete XMLHttpRequestObj;
}
}
} else {
Ajax.saveResponse(XMLHttpRequestObj.responseText);
delete XMLHttpRequestObj;
}
}
};
Here is the php:
$query = sprintf("INSERT INTO users (userName) VALUES (%s)", $format->formatValue($_POST['userName'));
$result = mysql_query($query, $connected) or die("Query Error: " . $query . " " . mysql_error());
echo mysql_insert_id();
NOTE: $format->formatValue just add quotes around variables.
The ajaxed page returns the following: "\r\n\1"
( The number, i.e. in this case 1 changes as per the mysql_insert_id() value )
itsallkizza
05-12-2009, 04:21 PM
without access to a php server right now i can't check, but take a look at your sprintf function, i think that may be producing the line breaks.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.