I have the following code:
var data = $(this).sortable('serialize');
$.ajax({
data: {order: data, actionFor: 'main_articles'},
type: 'POST',
url: 'updateDisplayOrder.php',
success: function (msg) { //re-number the rows from 1 to n
//code goes here
},
error: function () {
alert("An error occurred");
});
And the PHP:
require_once('../lib/common/db_connect.php');
$ids = array();
$actionFor = $_POST['actionFor'];
foreach ($_POST['order'] as $value) //error here {
//more code goes here
}
The problem is that I get this error on the foreach line:
Warning: Invalid argument supplied for foreach()
I noticed that if I change this line:
data: {order: data, actionFor: 'main_articles'},
To
data:data
And in the PHP :
foreach ($_POST['order'] as $value) //error here {
To
foreach ($_POST['item'] as $value)
It Works great. Why? How can I fox it? thanks!
foreach.var_dump($_POST['order']);?