Skip to content

Instantly share code, notes, and snippets.

@samshull
Created February 19, 2011 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samshull/835173 to your computer and use it in GitHub Desktop.
Save samshull/835173 to your computer and use it in GitHub Desktop.
function encode_users(data) {
var string = '';
$.each(data, function(index, info) {
string += '&users[' + index + '][onlineid]=' + encodeURIComponent(info.onlineid);
string += '&users[' + index + '][comment]=' + encodeURIComponent(info.comment);
});
return string;
}
$.ajax({
type: "POST",
url: "sync.php",
data: encode_users(users)
})
/*
encode_users([{onlineid: 1, comment: 1}, {onlineid: 2, comment: 2}])
returns :
"&users[0][onlineid]=1&users[0][comment]=1&users[1][onlineid]=2&users[1][comment]=2"
Which can be parsed by:
<?php
print_r($_POST['users']);
?>
Into:
Array
(
[users] => Array
(
[0] => Array
(
[onlineid] => 1
[comment] => 1
)
[1] => Array
(
[onlineid] => 2
[comment] => 2
)
)
)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment