jQuery ajax提交2个数据源(表单和数据表)

时间:2012-07-23 10:46:24

标签: jquery datatables

我有一个表单,我用jQuery ajax提交,但工作正常,但我还需要提交第二个数据源。

这是我到目前为止所做的:

<script type="text/javascript"> 
    var $j = jQuery.noConflict();
    $j(window).load(function(){     
        // this is the ID of your FORM tag
        $j("#send-form").submit(function(e) {
            e.preventDefault(); // this disables the submit button so the user stays on the page
            // this collects all of the data submitted by the form
            var str = $j(this).serialize();                  
               $j.ajax({               
               type: "POST", // the kind of data we are sending
               url: "<?php print $cs_base_dir; ?>sendmail.php", // this is the file that processes the form data
               data: str, sData, // this is our serialized data from the form
               success: function(msg){  // anything in this function runs when the data has been successfully processed

                    // this sets up our notification area for error / success messages
                    $j("#note").ajaxComplete(function(event, request, settings)
                    { 
                        if(msg == "OK") // Message Sent? Show the Thank You message and hide the form
                        {
                            // This is shown when everything goes okay
                            result = "<div id=\"message\" class=\"updated\">Your message has been sent.</div>";

                        }
                        else // if there were ewrrors
                        {
                            result = msg; // msg is defined in sendmail.php
                        }                                
                        $j(this).html(result); // display the messages in the #note DIV                          
                    });                  
                }                    
             });                     
        });         
    });
</script>

但是我还需要提交一些其他数据(数据表),我得到了这些数据:

var sData = $j('input', oTable.fnGetNodes()).serialize();

这是指定发送方式的页面:DataTables with form elements example

如何添加,以便提交表单和数据表?

由于 ç

1 个答案:

答案 0 :(得分:1)

尝试

data: str + "&" + sData

str和sData都是作为字符串发送的,取自DataTables页面上的示例,如下所示:“check8 = 8&amp; check9 = 9”。 所以你只需添加“&amp;”在他们之间送两个。