Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
FoxyCart API - Ajax to PHP and back for customer info
$.ajax({
url: '../assets/php/get_customer_id.php',
data: { email: "email@email.com" },
type: 'post',
success: function(data) {
var xmlDoc = $.parseXML(data),
$xml = $(xmlDoc);
console.log($xml.find("customer_id").text());
},
error: function(jqXHR, textStatus, errorThrown) {
console.log("ERROR", jqXHR, textStatus, errorThrown);
}
});
<?php
//Checks if action value exists
if (isset($_POST["email"]) && !empty($_POST["email"])) {
$email = $_POST["email"];
$foxy_domain = "yourdomain.foxycart.com";
$foxyData = array();
$foxyData["api_token"] = "XXX Your Key XXX";
$foxyData["api_action"] = "customer_get";
$foxyData["customer_email"] = $email;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://" . $foxy_domain . "/api");
curl_setopt($ch, CURLOPT_POSTFIELDS, $foxyData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
// If you get SSL errors, you can uncomment the following, or ask your host to add the appropriate CA bundle
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = trim(curl_exec($ch));
// The following if block will print any CURL errors you might have
if ($response == false) {
print "CURL Error: \n" . curl_error($ch);
} else {
print $response;
}
curl_close($ch);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment