Last active
August 30, 2021 01:08
-
-
Save atikju/8d94925333dc17de30591a78aee9ee9b to your computer and use it in GitHub Desktop.
PHP POST receiver from jQuery Ajax
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 | |
//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']; |
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
$(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