Iam trying to encode url of the xmlhttprequest method as utf-8
var Url=("http://localhost/day1/tryconnect.php?add="+address) ; // the server script to handle the request
if (window.XMLHttpRequest) {
xmlhttp= new XMLHttpRequest() ; // For all modern browsers
}
else if (window.ActiveXObject) {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP") ; // For (older) IE
}
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
alert("connection is stable") ;
}
xmlhttp.open("GET", Url, false);
xmlhttp.send(null);
var xml = xmlhttp.responseXML ;
i tried the following method to encode the Url .html
it didn't work for me
Iam trying to encode url of the xmlhttprequest method as utf-8
var Url=("http://localhost/day1/tryconnect.php?add="+address) ; // the server script to handle the request
if (window.XMLHttpRequest) {
xmlhttp= new XMLHttpRequest() ; // For all modern browsers
}
else if (window.ActiveXObject) {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP") ; // For (older) IE
}
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
alert("connection is stable") ;
}
xmlhttp.open("GET", Url, false);
xmlhttp.send(null);
var xml = xmlhttp.responseXML ;
i tried the following method to encode the Url http://www.webtoolkit.info/javascript-utf8.html
it didn't work for me
- If you want to encode a string use encodeURIComponent('your'+ string) or escape('your'+ string). Hope it helps you. – Jan Wiemers Commented Mar 21, 2012 at 10:54
- it didnt help in my case...the problem that in the url localhost/day1/tryconnect.php?add="+address (+address) is a special character word..and its being sent to php code via ajax request using the xmlhttprequest object...the special all am looking for is to probably encode this address in utf-8 so that it won't make any problems dealing with Chrome and IE..apparently the address is received corrupted and not encoded properly... – John silver Commented Mar 21, 2012 at 11:07
- solved :) stackoverflow./questions/332872/… – John silver Commented Mar 21, 2012 at 11:29
1 Answer
Reset to default 2Here's a great article on the subject of URLEncoding/Decoding in JavaScript: http://roneiv.wordpress./2007/12/25/how-to-do-proper-url-encoding-in-javascript-when-using-windowopen/
It uses a bination of encodeURI + escape
encodedParams += (p[0] + "=" + escape(encodeURI(p[1])));