2014-11-22 69 views
0

我是一个通过ajax发送结果的表单。使用“提交按钮”发送不是问题,但是当我更改“选择”字段时,没有数据被引用。它应该是一个“父母”问题,一些div和跨度位于输入字段的周围。 感谢您的帮助发送表单与父()。serialize()

  <form> 

      // calls the script by changing but no data is submited - there are some divs and spans around the "select" 
      <div id="e.g."> 
       <div> 
        <select id="version" size="1" name="version" class="change"><option value="1" selected>XXX</option><option value="2">YYY</option></select> 
       </div> 
      </div> 

      //calls the script by clicking and all datas are submited 
      <input id="submit_button" type="submit" value="Generate preview and HTML code"> 

      </form> 

      <script> 
      $(function(){ 
       function send() { 

       $.ajax({ 
        type: "POST", 
        url: "script.pl", 
        data: $(this).parent().serialize(), 
        success: function(msg) { 
        $('#xyz').html(msg); 
        } 
       }); 
       return false; 
       } 
       //send with the submit button 
       $("#submit_button").click(send); 
       //send when the select field is changed 
       $('.change').change(send); 

      }); 
      </script> 
+0

解决方案提供一个id,形成元素,然后用连载方式发送数据,如$(“#formid”)。序列化() – 2014-11-22 09:32:38

回答

0

找到自己

data: $('#id_of_the_form').serialize(),