Mysql doesn't save line breaks from jQuery ajax post?

I have a PHP / Mysql application that allows users to post text from a form. When I paste text from an HTML text box into my mysql table, it does not save carriage returns / line breaks. Text is not stored in DB as "Hey SO, \ n This is a new line." It is stored with a space in the column (exactly the same as it is typed), but for me there is no way to output it using nl2br()and save breaks. I avoid before embedding text like this:

$foo_text = mysql_real_escape_string(ucfirst($_POST['foo_text']));

But even if I delete everything and just use the POST parameter, it still does the same. Will this have anything to do with me for serializing and publishing this form via ajax (I use JQUERY)? I have found https://stackoverflow.com/a/3166269/2126328 , but in fact I do not see the solution. I am sending from:

$.ajax({
        type: "POST",
        url: "insertFooBar.php",
        data: $("#foo_form").serialize(),
        success: function(msg) {
            ETC...
        }
    })

Is there anything really obvious I'm missing here? I am stuck...

Thanks in advance for your help!

+5
source share
3 answers

. serialize() . $("#foo_bar").replace( /\n/g, '<br>' )) , . , , , .

+2

, % D0% DA, , jQuery % 0A.

() , , , , , :

keepLB (str) {

var reg = new RegExp ( "(% 0A)", "g" ); return str.replace(reg, "% 0D $1" ); }

$.post().

, !

+3

HTML- , , , AJAX.

AJAX? ? jQuery , AJAX .

AdoDB, . . / , . AdoDB:

$data['foo_text'] = ucfirst($_POST['foo_text']);
$adodb->AutoExecute($tablename, $data, 'UPDATE', "id=$id");

, .

+1

All Articles