Skip to content

Instantly share code, notes, and snippets.

@Shakil-Shahadat
Last active January 16, 2021 03:58
Show Gist options
  • Save Shakil-Shahadat/b8c910b897117cb367b203c928ff3cc2 to your computer and use it in GitHub Desktop.
Save Shakil-Shahadat/b8c910b897117cb367b203c928ff3cc2 to your computer and use it in GitHub Desktop.
POST Request by Fetch
<?php
header( 'Access-Control-Allow-Origin: *' );
print_r( $_POST );
fetch( 'post.php',
{
method: 'POST',
headers: { 'Content-Type' : 'application/x-www-form-urlencoded' },
body: 'data1=Hello World!&data2=Hello Universe!'
})
.then( response => response.text() )
.then( data => console.log( data ) )
.catch( error => console.error( 'Error:', error ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment