Skip to content

Instantly share code, notes, and snippets.

@wouterverweirder
Last active April 6, 2017 09:22
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 wouterverweirder/ee134201852138946856 to your computer and use it in GitHub Desktop.
Save wouterverweirder/ee134201852138946856 to your computer and use it in GitHub Desktop.
<?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