Skip to content

Instantly share code, notes, and snippets.

@chrisamoore
Created February 28, 2013 23:45
Show Gist options
  • Save chrisamoore/5061163 to your computer and use it in GitHub Desktop.
Save chrisamoore/5061163 to your computer and use it in GitHub Desktop.
Variable Object properties in JS
<?php
print_r((object)$_POST);
<!doctype html>
<html>
<head>AJAX OBJ TEST</head>
<body>
Testy AJAX !
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
$(document).ready(function($) {
var foo = {};
foo.string = 'string',
foo.number = 1,
foo.array = [1,'string', {foo:'foo'}],
foo.obj = {
number : 1,
string : 'string',
array : [1, 'string', { foo: 'foo'}],
obj : {foo: 'foo'}
};
console.log(foo);
var elmts = ['foo', 'bar', 'baz'];
var bar = {};
for (var i = 0; i < elmts.length; i++) {
bar[elmts[i]] = 'foo';
}
console.log('variable object properties');
console.log(bar);
$.ajax({
url: 'handler.php',
type: 'post',
data: {data : foo},
success: function(data) {
console.log('response');
console.log(data);
}
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment