Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在jquery中获取文本区域值?_Php_Jquery_Html_Ajax_Textarea - Fatal编程技术网

Php 如何在jquery中获取文本区域值?

Php 如何在jquery中获取文本区域值?,php,jquery,html,ajax,textarea,Php,Jquery,Html,Ajax,Textarea,我试图将文本区域的值发送到数据库中,但无法获取文本区域的值。而且,一旦数据保存到数据库中,我想在文本区域中显示该数据。请帮帮我 谢谢。 这是我的密码 <script type="text/javascript" > function save() { var mail = { aboutus: $('textarea#area1').val(), services: $("#area2").val(),

我试图将文本区域的值发送到数据库中,但无法获取文本区域的值。而且,一旦数据保存到数据库中,我想在文本区域中显示该数据。请帮帮我

谢谢。 这是我的密码

<script type="text/javascript" >
function save()
{
var mail = {
                aboutus: $('textarea#area1').val(),
                services: $("#area2").val(),
                contact: $("#area3").val()

              };
        $.ajax({
                url: "user_stall_add.php",
                type: "POST",
                enctype: "multipart/form-data",
                data: mail,

                success: function(data) {

alert("Content Added");



                }
            });
            }
</script>
<script type="text/javascript" src="../nicEdit.js"></script>
<script type="text/javascript">
bkLib.onDomLoaded(function() { nicEditors.allTextAreas() });
</script>

<h4 style="margin-left:4em;">About Us Content</h4>
<textarea name="area1" id="area1"  style="margin-left:4em;" cols="60" rows="10"></textarea>

<input type="button" style="margin-left:4em;" value="Save" onclick="save();"><br />

<h4 style="margin-left:4em;">Services Content</h4>
<textarea  name="area2" id="area2"  cols="60" rows="10">
Some Initial Content was in this textarea
</textarea>
<input type="button" style="margin-left:4em;" value="Save" onclick="save();"><br />

<h4 style="margin-left:4em;">Contact Content</h4>
<textarea style="margin-left:4em;" id="area3" name="area3" cols="60" rows="10">
HTML <b>content</b> <i>default</i> in textarea
</textarea>
<input style="margin-left:4em;" type="button" value="Save" onclick="save();"><br />
</div>

函数save()
{
var邮件={
aboutus:$('textarea#area1').val(),
服务:$(“#区域2”).val(),
联系人:$(“#区域3”).val()
};
$.ajax({
url:“user\u stall\u add.php”,
类型:“POST”,
enctype:“多部分/表单数据”,
数据:邮件,
成功:功能(数据){
警报(“添加内容”);
}
});
}
onDomLoaded(函数(){nicEditors.allTextAreas()});
关于我们的内容

服务内容 一些初始内容在这个文本区域
联系内容 文本区域中的HTML内容默认值
请尝试
$('#area1').val()
以匹配其他文本区域。另外,请确保textarea中有一个值,否则将得到一个未定义的值。最后,当我只使用

function test() {
  // These both work for me.
  console.log($("textarea#area1").val());
  console.log($('#area1').val());
}
试一试


您使用了
niceditor

          var aboutus  = new nicEditors.findEditor('area1').getContent();            
          var services  = new nicEditors.findEditor('area2').getContent();             
          var contact  = new nicEditors.findEditor('area3').getContent();

          var mail = {
            aboutus: aboutus,
            services: services,
            contact: contact

          };
参考:

文件:

返回实例的当前HTML

例如:

nicEditors.findEditor('myArea2').getContent();
返回内容编辑器中用ID“myArea2”替换页面上元素的HTML。

.val()
应该可以工作。为什么你认为它不起作用?
nicEditors.findEditor('myArea2').getContent();