Hi all
In a bit of a pickle with AJAX/PHP so i hope osmeone can point out the error of my ways.
I have a textarea and using the onblur event I call an ajax function which ultimately updates my database with the textarea content thus removing the need for a submit button. I have this working great but for some reason my line breaks are being removed from the string by the time it gets to my UPDATE/INSERT query and I can't see why.
Is this a known issue?
In the onblur event of the textarea I am sending the contents to my ajax function by using 'this.value' and when I alert() the value, it has the line breaks which is OK. However, somewhere after this my line breaks are being removed. This is in my ajax function:
if (xmlNewHttp) {
// try to connect to the server
try {
xmlNewHttp.open("GET", "/ajaxanswers.php?qn="+questionnumber+"&ao="+answeroption+"&st="+sectext+"§ionid="+sectionid+"", true);
xmlNewHttp.onreadystatechange = saveQuestionAnswerResponse;
xmlNewHttp.send(null);
}
// display error in case of failure
catch(e) {
alert("Cannot connect to the server!");
}
}
and in my PHP I have this:
$sectionid = $_REQUEST['sectionid'];
$question = $_REQUEST['qn'];
$answer = $_REQUEST['ao'];
$usefield = $_REQUEST['st'];
I have tried nl2br around the variable an all sorts - any ideas whats going on!!?
Thanks