0

I have a form that I'm submiting with jQuery ajax which works fine but I also need to submit a second data source.

this is what I have so far:

<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>

But I also have some other data (datatables) I need to submit as well which I get with this:

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

This is the page that specifies how to sent it: DataTables with form elements example

How do I add this so both form and datatables are submitted?

Thanks C

1
  • found this: data: { json_1:$.toJSON(data_1), json_2:$.toJSON(data_2) }, is this what I need? Commented Jul 23, 2012 at 11:27

1 Answer 1

1

Try

data: str + "&" + sData

Both str and sData are sent as strings which, taken from the example on the DataTables page, look like this: "check8=8&check9=9". So you just add the "&" in between them to send both.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.