Reputation: 399
I'm trying to avoid the pesky page reload and trying to dynamically reload a div when the user submits a form. However, although the data does get passed successfully and the output of the serialized data is correct, I am not able to access these in the PHP file.
Here is my code:
<script>
var submiting = false;
function submitmyforum()
{
alert($('#filter_form').serialize());
if (submiting == false)
{
submiting = true;
$.ajax({
type: 'post',
url: 'index.php',
data: $('#filter_form').serialize(),
success: function(data, status, jqXHR) {
$('#clublist').html($(data).filter('#clublist').contents());
alert('submitted');
submiting = false;
}
});
}
else
{
alert("Still working ..");
}
}
</script>
<?php
if (isset($_POST['location'])) {
echo "Location was set";
}
?>
Now, in my HTML I have multiple checkbox options with the name = "location[]". Besides, the web site is working fine with the traditional page reload technique in which the form submits the values to the same page via POST method.
So I am kind of sure that there is nothing wrong at the HTML front. I am awaiting a solution.
Upvotes: 0
Views: 1037
Reputation: 8809
If you want get data as post then you should use:
serializeArray() instead of serialize()
Because serializeArray()
creates an array which is not a JSON array. I suggest you to change it in your code and try to access the data as $_POST
.
Upvotes: 1