Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XMLhttpObject 1

Status
Not open for further replies.

seanybravo

IS-IT--Management
Sep 24, 2003
89
GB
XMLhttpObject.send

I have been working on using this object to create AJAX style webpages what I have found is that when I send commands using POST all of the spaces get removed. Has anyone come across this problem before and got a work around?

I have tried to replace the spaces with underscores and change them back but I thought it was worth a post to see it someone had a better solution or workaround.

Sean
 
try
Code:
xmlhttp.preserveWhitespace = true;



I don't know the answer but my good friend Google does.
 
Thank you for your feedback, however I still have had no joy. Here is an example of my code.

Code:
function GetXmlHttpObject(url, handler, id, strSend) { 

var objXmlHttp=null

alert(strSend)

try {objXmlHttp = new XMLHttpRequest();			
		}
		catch(e){
			try{objXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
			catch(e){
				try{objXmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			}	
				catch(e){alert("error opening XMLHTTP")
				}
			}
		}
		
objXmlHttp.onreadystatechange=function(){
	if (objXmlHttp.readyState==4 || objXmlHttp.readyState=="complete"){
		handler(objXmlHttp, id)
	}
	}

	objXmlHttp.preserveWhiteSpace = true
	objXmlHttp.open("POST",url,true)
	objXmlHttp.setRequestHeader("Content-Type", "application/x-[URL unfurl="true"]www-form-urlencoded")[/URL]
	objXmlHttp.send(strSend)
} 


function stateChanged2(obj,id){
		document.getElementById(id).innerHTML=obj.responseText	
}

function RecordCountPrice(obj,id){
var s
s=""
s = obj.responseText

alert("Returned " + s)

}
 
Space is urlencoded to "+". But in the case of post, you can safely use escape() function to encode it to %20. Like this.
> objXmlHttp.send(strSend)
[tt]objXmlHttp.send(escape(strSend))[/tt]
For more rigorous urlencoding space, you can do this.
[tt]objXmlHttp.send(strSend.replace(/ /g,"+")[/tt]
 
Great now works like a charm. Is there any reference for urlencoding I have been looking at this problems for most of the day.

Many thansk for your help.

Sean
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top