gamesmstr Posted January 30, 2009 Share Posted January 30, 2009 I have a ajaxed chat room and have run across an interesting problem. My post_chat() function seems to strip out the + and & signs. I could use some help here. I am guessing it happens when the variable is passed as POST. Anybody got any ideas? here is my ajax call: var intUpdate; function createXMLHttpRequest() { if (typeof XMLHttpRequest != 'undefined') { return new XMLHttpRequest(); } try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } return false; } function refresh_chat() { var xmlHttp2 = createXMLHttpRequest(); params = ''; xmlHttp2.open("POST","ajax/ajax-autochat3.php", true); xmlHttp2.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlHttp2.onreadystatechange = function() { if(xmlHttp2.readyState == 4 && xmlHttp2.status == 200) { document.getElementById("chatbox").innerHTML = xmlHttp2.responseText; } } xmlHttp2.send(params); intupdate=setTimeout("refresh_chat()", 10000); } function refresh_stats() { var xmlHttp3 = createXMLHttpRequest(); params = ''; xmlHttp3.open("POST","ajax/statsajax.php", true); xmlHttp3.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlHttp3.onreadystatechange = function() { if(xmlHttp3.readyState == 4 && xmlHttp3.status == 200) { var brokenstring = xmlHttp3.responseText.split("-@[-"); if ( brokenstring[0] == 'stats' ) { document.getElementById("statbox").innerHTML = brokenstring[1]; } } } xmlHttp3.send(params); statupdate=setTimeout("refresh_stats()", 60000); } function load_chat() { var xmlHttp4 = createXMLHttpRequest(); params = ''; xmlHttp4.open("POST","ajax/ajax-autochat3.php", true); xmlHttp4.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlHttp4.onreadystatechange = function() { if(xmlHttp4.readyState == 4 && xmlHttp4.status == 200) { document.getElementById("chatbox").innerHTML = xmlHttp4.responseText; } } xmlHttp4.send(params); setTimeout("refresh_chat()", 10000); } function post_chat() { var xmlHttp5 = createXMLHttpRequest(); var text = document.getElementById("chatval").value; params = "text=" + text; xmlHttp5.open("POST","ajax/ajax-autochat3.php", true); xmlHttp5.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlHttp5.onreadystatechange = function() { if(xmlHttp5.readyState == 4 && xmlHttp5.status == 200) { document.getElementById("chatbox").innerHTML = xmlHttp5.responseText; } } xmlHttp5.send(params); document.getElementById("chatval").value=''; clearTimeout(intupdate); refresh_chat(); } Link to comment https://forums.phpfreaks.com/topic/143125-solved-stripped-characters-on-post/ Share on other sites More sharing options...
rhodesa Posted January 30, 2009 Share Posted January 30, 2009 try changing this: params = "text=" + text; to params = "text=" + encodeURI(text); in your post_chat() function Link to comment https://forums.phpfreaks.com/topic/143125-solved-stripped-characters-on-post/#findComment-750608 Share on other sites More sharing options...
gamesmstr Posted January 30, 2009 Author Share Posted January 30, 2009 try changing this: params = "text=" + text; to params = "text=" + encodeURI(text); in your post_chat() function Thanks! I actually had to use encodeURIComponent() but you definitely put me on the right track. Link to comment https://forums.phpfreaks.com/topic/143125-solved-stripped-characters-on-post/#findComment-750627 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.