I have been trying to post Array and Form data together but seems like I am getting JavaScript errors. When I tried to post Only array data without adding form data it works fine.
I am having a Dropdown Select Box and few CheckBoxes. I wanted to post SelectBox data and CheckBox data together, so I had saved the CheckBox data's into array since it is a multi Select CheckBox.
In the below code i need to resolve issue with this
data: datasel+"&id="+$("#member_id").val(), //Error in this line only. To be Fixed!!
Here is the Complete code
<script>
$(document).ready(function(){
$("#err").css('display', 'none', 'important');
$("#submit_issueBook").click(function(){
//Creating Array and adding data
var datasel = { 'selector[]' : []};
$(":checked").each(function() {
datasel['selector[]'].push($(this).val());
});
$.ajax({
type: "POST",
url: "includes/issue_book.php",
//data: "submit_addMember="+$("#submit_addMember").val(), <-- Default format for sending post data
data: datasel+"&id="+$("#member_id").val(),
if($.trim(html)=='true'){
$("#err").addClass("alert alert-success err-inline");
$("#err").html("<strong>Member details updated Successfully</strong>");
window.location="<?php basename($_SERVER['PHP_SELF']); ?>";
}
else{
$("#err").addClass("alert alert-danger err-inline");
$("#err").html("<img src='images/caution-icon.png' />"+$.trim(html));
}
},
beforeSend:function()
{
$("#err").css('display', '-webkit-inline-box', 'important');
$("#err").addClass("err-inline");
$("#err").html("<img src='images/loading.gif' /> Loading...")
}
});
return false;
});
});
</script>
PHP code to catch this data is
if( isset( $_POST['selector'] ) )
{ $id=$_POST['id'];
$data=$_POST['selector'];
for ( $i=0; $i < count( $data ); $i++ )
{
//Some SQL query
}
}
Any help would be appreciated. Thanks :)