$("#doStatus").click(function()
{
var serialized = $("#formStatus").serialize()
$.get("<?echo $site['url'];?>modules/yobilab/tuitting_core/classes/doStatusBox.php", serialized);
window.setTimeout('location.reload()', 1000);
return false;
});
This code will return something like this:
tuitting=test&f%5B%5D=2&f%5B%5D=4&f%5B%5D=8&t%5B%5D=2&t%5B%5D=3&t%5B%5D=4
Where tuitting(the first value) is the value of the textarea, then we have:
-f this is the name of somecheckboxes that have the same names but different values
-t other checkboxes, same names, different values
As you may see the serialized function for "f" and "t" returns strange values, when they should only be simple number, like tuitting=test&f=1&f=3&t=9&t=10
Now when the ajax call the doStatusBox.php file nothing happens.
The doStatusBox.php file is made by a simple foreac开发者_StackOverflow中文版h php loop.
It will take the below variables:
$_GET['tuitting']
$_GET['t']
$_GET['f']
Foreach `$_GET['t'] and $_GET['f'] the loop will insert the relative values into the database.
This is not working at all. The php foreach can not recognize the results given by the jQuery serialize function and does not do simply anything.
What is the problem?
I should use another function instead of foreach?
Or the problem is in the jQuery serialized function?
Please help me. `
Since we cannot see your HTML code, I can't say for sure what the problem is, but I suspect it's one of two problems:
(most likely) - your checkbox fields need to have a [] after the name. Example: name="t[]". If all of your checkboxes are name="t", then when multiple are posted, PHP will only see one of them. However, if you put brackets at the end of the name PHP will recognize the collection of values as an array that you can loop through.
(less likely) - the PHP script that receives this data should run urldecode() on the data. Example: $tuitting = urldecode($_GET['tuitting']);
Hope this helps!
精彩评论