通过ajax从textarea传递文本

时间:2018-01-23 19:09:29

标签: jquery

我试图从我的表单上的textarea中获取文本并将其通过ajax传递到我的数据库中。由于某种原因,它只是给了我一个空的结果" coverletter"

我的代码是

 <textarea id="elm1" required></textarea>

JS

<script type="text/javascript">
$(document).ready(function () {

            $("#apply").click(function(e) {
                    e.preventDefault();
                     var coverletter = $("#elm1").val();
             var oppid = "1";
             var networkid = "10294";

                    $.ajax({
                            url: "/opportunity/apply",
                            method: "POST",
                            data: {coverletter:coverletter, oppid:oppid, networkid:networkid},
                            success: function(data) {
                                 $("#thecontent").html(data);

                            },
                            error: function() {
                                    alert("Please enter valid email id!");
                            }
                    });
            });




    if($("#elm1").length > 0){
        tinymce.init({
            selector: "textarea#elm1",
            theme: "modern",
            height:200,
            plugins: [
                "advlist autolink link pagebreak spellchecker",
                "wordcount nonbreaking",

            ],
                             menubar: "",
            toolbar: "bold italic underline|",

        });
    }
});

来自firebug inspect的POST响应是: coverletter networkid 10294 oppid 1

Source coverletter=&oppid=1&networkid=10294

我甚至添加了alert (coverletter);

它只是给出一个空的警报窗口。

1 个答案:

答案 0 :(得分:1)

怎么样......

var coverletter = tinymce.get('elm1').getContent();

var coverletter = tinymce.activeEditor.getContent();