如何插入AJAX textarea

时间:2016-10-17 06:19:44

标签: php ajax wordpress

您好我在为ajax PLease插入textarea时遇到了麻烦,这有助于我弄清楚什么是错误的。谢谢

      $('#submit').click(function(){
         var message_options     =  $('#message_options').val();         

         $.ajax({
                type: "post",
                url: ajax_params.ajax_url,
                data: {"action": "data", 
                "message_options":message_options,
         },
                success: function(data){
          }
        });  
      });

PHP函数:

      function data(){
      global $wpdb;
      $message_options = $_POST['message_options'];

                 $result2 =  $wpdb->insert( $table_client_event_details , 
                   array( 
                     'contact_person_id'=>$wpdb->insert_id,
                     'message_options'=> $message_options,
                    )
                 );
      }

1 个答案:

答案 0 :(得分:0)

我只是改变了这个

 $('#submit').click(function(){
     var message_options     =  $('textarea').val(); // I change the element id to textarea. I dont know why if I use ID does not working. Thank you

     $.ajax({
            type: "post",
            url: ajax_params.ajax_url,
            data: {"action": "data", 
            "message_options":message_options,
     },
            success: function(data){
      }
    });  
  });