I do not have much experience with $_GET
. I try to always use POST method, so I may be missing something obvious.
I am utilizing a plugin, which sends a request to server via GET method, with a value in a serialized form done with jQuery serialize()
out of a form.
Normally, at least when working with $_POST
, the value would be readily available to be assigned to a working variable at the receiving PHP file. This is not happening as far as I can tell.
It keep its serialized representation. When I tried to unserialize it with $array = unserialize($string)
, it gave a bool(false)
return.
A var_dump($_GET)
on the receiving end gives this as an example:
array(2) {
["hook"]=>
string(15) "hook%5B2%5D=107"
["_"]=>
string(13) "1364920519074" //This is a serial no. generated by the plugin
}
A var_dump($_POST)
in a similar situation would show directly the value '107', which is what I am looking for.
I appreciate your help.
Here is the Javascript:
$(document).ready(function () {
var str;
oTable = $("#myTable").dataTable({
"fnServerParams": function (aoData) {
aoData.push({
name: 'hook',
value: str
});
},
});
$("#filter").change(function () {
str = $("#filter").serialize();
oTable.fnReloadAjax("filter_prange.php");
});
});
For future reference I am showing the revised script after comments from Scones. So the solution was to get back to the originating php file and change the way the values were retrieved. The method of getting the values from the form was changed from serialize() in order to accomodate the plug in, which can only deal with hard numbers. So this actually show 2 different way of retrieving the values out of checked check-boxes. I amended the title accordingly.
<script>
$(document).ready(function() {
var str = [];
oTable = $("#myTable").dataTable({
"fnServerParams": function (aoData) {
aoData.push({ name:'str', value:str });}
});
$("#filter").change(function(){
str=[];
$('#filter :checked').each(function() {
str.push($(this).val());
});
oTable.fnReloadAjax("filter_prange.php");
});
});
And this is the form that triggers all this:
<form id = "filter">
<input class="hook1" type="checkbox" value="115" name="hook[0]">
<input class="hook1" type="checkbox" value="116" name="hook[1]">
<input class="hook1" type="checkbox" value="107" name="hook[2]">
</form>