send object in post request javascript code example
Example 1: javascript send post request
let data = {element: "barium"};
fetch("/post/data/here", {
method: "POST",
body: JSON.stringify(data)
}).then(res => {
console.log("Request complete! response:", res);
});
window.post = function(url, data) {
return fetch(url, {method: "POST", body: JSON.stringify(data)});
}
post("post/data/here", {element: "osmium"});
Example 2: post object
<?php
$featured_post = get_field('featured_post');
if( $featured_post ): ?>
<h3><?php echo esc_html( $featured_post->post_title ); ?></h3>
<?php endif; ?>