Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Posts
    205
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Response Text Prepending \r\n

    The ajax response text is prepending "\r\n" to every response. Is there a way to eliminate the added return and newline characters?

    Thanks.

  • #2
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    can you post the javascript code you have? and possibly the output of the ajaxed page, or a link to the ajaxed page?
    Feel free to e-mail me if I forget to respond ;)
    ohsosexybrit@gmail.com

  • #3
    Regular Coder
    Join Date
    Sep 2008
    Posts
    205
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by itsallkizza View Post
    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 :
    Code:
    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:
    Code:
    $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 )

  • #4
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    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.
    Feel free to e-mail me if I forget to respond ;)
    ohsosexybrit@gmail.com


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •