Skip to content

Instantly share code, notes, and snippets.

@atikju
Last active August 30, 2021 01:08
Show Gist options
  • Save atikju/8d94925333dc17de30591a78aee9ee9b to your computer and use it in GitHub Desktop.
Save atikju/8d94925333dc17de30591a78aee9ee9b to your computer and use it in GitHub Desktop.
PHP POST receiver from jQuery Ajax
<?php
//Allow CORS
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: X-Requested-With");
//Allow CORS ends
echo $_GET['first_name'];
$(document).ready(function(){
var first_name = $('#firstname').val();
var last_name = $('#lastname').val();
var email = $('#email').val();
var phone = $('#phone').val();
var note = $('#note').val();
if($('#primary_phone').is(':checked')){
var tag = $('#primary_phone').val();
}else{
var tag = 'primary_email';
}
var data = {
first_name : first_name,
last_name: last_name,
email: email,
phone: phone,
note: note,
tag: tag
};
$.ajax({
method: 'GET',
crossDomain: true,
dataType: 'jsonp',
crossOrigin: true,
data: data,
headers: {
'Access-Control-Allow-Methods': '*',
"Access-Control-Allow-Credentials": true,
"Access-Control-Allow-Headers" : "Access-Control-Allow-Headers, Origin, X-Requested-With, Content-Type, Accept, Authorization",
"Access-Control-Allow-Origin": "*",
"Control-Allow-Origin": "*",
"cache-control": "no-cache",
'Content-Type': 'application/json'
},
url: 'https://four-seasons.storehelps.com/index.php',
success: function(response){
console.log("Respond was: ", response);
},
error: function (error) {
console.log("There was an error: ", error);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment