aliento Posted May 31, 2009 Share Posted May 31, 2009 Hi! I am posting html source through POST with ajax. But when into the source i post appears the symbol & it recognize it as variable separator and doesnt load all the html source. ajax : function preview(){ var http = new XMLHttpRequest(); var url = 'preview.php'; var html = document.getElementById('html_source').value; var params = 'html='+html; http.open("POST", url, true); http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.setRequestHeader("Content-length", params.length); http.setRequestHeader("Connection", "close"); http.onreadystatechange = function() { if(http.readyState == 4 && http.status == 200) { Shadowbox.open({ content: 'temp/preview.htm', player: 'iframe', title: 'Preview', height: 600, width: 800, options: {} }); }; } http.send(params); } If it finds & it load all the string after as another variable. I think this is generic problem. Is there any solution? Thank you Link to comment https://forums.phpfreaks.com/topic/160374-solved-post-data-with-ajax-but-this-stops-the-data/ Share on other sites More sharing options...
anupamsaha Posted May 31, 2009 Share Posted May 31, 2009 Change: var params = 'html='+html; To: var params = 'html='+escape(html); Link to comment https://forums.phpfreaks.com/topic/160374-solved-post-data-with-ajax-but-this-stops-the-data/#findComment-846319 Share on other sites More sharing options...
aliento Posted May 31, 2009 Author Share Posted May 31, 2009 thanks you but it still doesnt work. Link to comment https://forums.phpfreaks.com/topic/160374-solved-post-data-with-ajax-but-this-stops-the-data/#findComment-846322 Share on other sites More sharing options...
aliento Posted May 31, 2009 Author Share Posted May 31, 2009 The problem now is that it doesnt parse utf-8 characters (Greek) Link to comment https://forums.phpfreaks.com/topic/160374-solved-post-data-with-ajax-but-this-stops-the-data/#findComment-846328 Share on other sites More sharing options...
aliento Posted May 31, 2009 Author Share Posted May 31, 2009 Great with your guidenes i found this s encodeURIComponent(html) which is for UTF-8. Thank you Link to comment https://forums.phpfreaks.com/topic/160374-solved-post-data-with-ajax-but-this-stops-the-data/#findComment-846330 Share on other sites More sharing options...
anupamsaha Posted May 31, 2009 Share Posted May 31, 2009 Great with your guidenes i found this s encodeURIComponent(html) which is for UTF-8. Thank you Yes. Also, read this: http://www.dangrossman.info/2007/05/25/handling-utf-8-in-javascript-php-and-non-utf8-databases/ This will answer your query. Cheers! Link to comment https://forums.phpfreaks.com/topic/160374-solved-post-data-with-ajax-but-this-stops-the-data/#findComment-846331 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.