Reputation: 2606
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
Upvotes: 0
Views: 1060
Reputation: 549
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.
Upvotes: 1