Vivid Lust Posted February 5, 2010 Share Posted February 5, 2010 High all, im having trouble with the thread title. The text in a textarea is passed via url to a php web page (using ajax) when it's passed the line breaks are lost so therefore nl2br is not effective - any ideas on how I can get around this ? thanks all Quote Link to comment https://forums.phpfreaks.com/topic/191065-phpjavascriptajax-line-break-problem/ Share on other sites More sharing options...
bbaker Posted February 5, 2010 Share Posted February 5, 2010 Why are you sending it via url (get)? You can/should use post method. Using get can cause issues with the url being too long & is likely the issue with line breaks. Quote Link to comment https://forums.phpfreaks.com/topic/191065-phpjavascriptajax-line-break-problem/#findComment-1007480 Share on other sites More sharing options...
Psycho Posted February 5, 2010 Share Posted February 5, 2010 There's nothing specific I am aware of that passing data on the query string will remove line breaks. You didn't post any code so it is difficult, if not impossible, to troubleshoot your problem. Sounds like the data is passing through multiple technologies/processes. You will need to test the input/output at each stage to determine where the break is occuring. I did a simple test with sending data with line breaks on the query string and was able to use nl2br() without a problem. Quote Link to comment https://forums.phpfreaks.com/topic/191065-phpjavascriptajax-line-break-problem/#findComment-1007482 Share on other sites More sharing options...
Vivid Lust Posted February 6, 2010 Author Share Posted February 6, 2010 This is my code How could I change it so that It uses the post method instead of get? function addComment(moodUpdater,moodID){ if( document.getElementById('commentText').value != ""){ var ajaxRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ } } var commentText = document.getElementById('commentText').value; var queryString = "?commentText=" + escape(commentText) + "&moodID=" + moodID + "&moodUpdater=" + moodUpdater; ajaxRequest.open("GET", "/ajax/addComment.php" + queryString, true); ajaxRequest.send(null); } } Thanks all, lots! Quote Link to comment https://forums.phpfreaks.com/topic/191065-phpjavascriptajax-line-break-problem/#findComment-1007921 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.