使用 JQuery 通过 Ajax Post 向服务器发送请求时删除新行 [英] remove new line when sending request to server via Ajax Post with JQuery

查看:23
本文介绍了使用 JQuery 通过 Ajax Post 向服务器发送请求时删除新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 Ajax 与 JQuery 一起使用,我想要做的只是使用 Ajax 将多行文本框值发送到 php.

I'm trying to use Ajax with JQuery, what I want to do is just send multiline textbox value to php with Ajax.

我正在使用该代码,它将 txtAnswer 值发送到 php,不幸的是,它从数据中删除了新行 ( ).我该如何解决这个问题...提前致谢.

I'm using that code, it sends txtAnswer value to php, unfortunately, it removes new lines ( ) from data. How can I solve this problem... Thanks in advance.

$.post(
    'post-answer.php', 
     {
        answer: $("#txtAnswer").val(),
        qid: <?= $question_ID ?>
     },
     function (ajaxResponse) {
        $('#answers').html(ajaxResponse)
     }
   );

推荐答案

Try: escape( $("#txtAnswer").val() )

=-)

这篇关于使用 JQuery 通过 Ajax Post 向服务器发送请求时删除新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆