dongzhanlian6289 2014-02-08 21:12
浏览 62
已采纳

jquery POST不发送textarea?

I am using the following script to handle a contact form:

$(document).ready(function(){
 /* attach a submit handler to the form */
 $("#contact_form").submit(function(event) {
 /* stop form from submitting normally */  
 event.preventDefault();

/* get some values from elements on the page: */
var $form = $( this ),
//Get the first value
nombre= $form.find( 'input[name="nombre"]' ).val(),
   //get second value
  email = $form.find( 'input[name="email"]' ).val(),
//get thirdvalue
mensaje = $form.find( 'input[name="mensaje"]' ).val(),    
//get the url. action="count.php"
url = $form.attr( 'action' );

  /* Send the data using post */
  var posting = $.post( url, { nombre: nombre, email: email, mensaje: mensaje} );

/* Put the results in a div */
posting.done(function( data ) {

$( "#contact_form" ).empty().append( data );
});
});
});    

Then conctact.php sends an email and shows either a succes or failure message:

<?php
        if (isset($_POST['email']))
           //if "email" is filled out, send email
          {
           //send email
          $email = $_POST['email'] ;
           $nombre = $_POST['nombre'] ;
           $mensaje = $_POST['mensaje'] ;

            mail("some.weird.email.address@server.com", $nombre,
           $mensaje,  $email);

            echo "<div data-alert class='alert-box success radius'>
              Su mensaje nos ha sido enviado.<br>Agradecemos que se haya comunicado con 
                 nosotros.
               <a href='#' class='close'>&times;</a>
               <a href='index.html'>Volver al sitio</a>
               </div>";

           }

          else {
             echo "<div data-alert class='alert-box warning radius'>
              Pedimos disculpas, no hemos podido enciar el mensaje.
               <br>Por favor vuelva a
               intentarlo más tarde.
               <a href='catalejo.info/index.html'>Volver al sitio</a>

               <a href='#' class='close'>&times;</a>
               </div>";
            }
        ?>

The form has three values, two inputs and a textarea, the input's values are passing but the textarea's is not. What could be the problem here? Any help will be appreciated.

  • 写回答

1条回答 默认 最新

  • dongyunwei8596 2014-02-08 21:18
    关注

    i suppose that this is the textarea :

    mensaje = $form.find( 'input[name="mensaje"]' ).val(),
    

    this line is for input not for textarea you should replace it with this :

    mensaje  = $form.find('textarea[name="mensaje"]').val();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动