Created
February 28, 2013 23:45
-
-
Save chrisamoore/5061163 to your computer and use it in GitHub Desktop.
Variable Object properties in JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
print_r((object)$_POST); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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