Last active
April 6, 2017 09:22
-
-
Save wouterverweirder/ee134201852138946856 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
if(!empty($_POST['elementen'])) { | |
/* | |
//print_r($_POST['elementen']); | |
foreach ($_POST['elementen'] as $value) { | |
//print_r($value); | |
} | |
*/ | |
$result = array( | |
'success' => true, | |
'id' => 123, | |
'numElementes' => sizeof($_POST['elementen']) | |
); | |
header('Content-Type: application/json'); | |
echo json_encode($result); | |
die(); | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title>Demo</title> | |
</head> | |
<body> | |
<script src="jquery.min.js"></script> | |
<script> | |
var items = []; | |
items.push({ | |
id: 1, | |
x: 100, | |
y: 150, | |
title: 'hello world', | |
authors: [ | |
'Wouter Verweirder', | |
'Frederik Jacques' | |
] | |
}); | |
items.push({ | |
id: 1, | |
x: 130, | |
y: 110, | |
title: 'hello' | |
}); | |
items.push({ | |
id: 1, | |
x: 200, | |
y: 340, | |
url: 'http://placekitten.com/100/100' | |
}); | |
$.ajax({ | |
type: "POST", | |
url: 'index.php', | |
data: {elementen: items}, | |
success: function(data) { | |
console.log('success'); | |
console.log('aantal elementen: ', data.numElementes); | |
}, | |
error: function(error) { | |
console.log('error'); | |
console.log(error); | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment