Skip to content

Instantly share code, notes, and snippets.

@ccnixon
Forked from subnetmarco/CorsRequest.js
Created February 17, 2016 19:39
Show Gist options
  • Save ccnixon/18489df61947ff1808b8 to your computer and use it in GitHub Desktop.
Save ccnixon/18489df61947ff1808b8 to your computer and use it in GitHub Desktop.
Sample code for executing an AJAX request using jQuery.
$.ajax({
url: 'MASHAPE-URL', // The URL to the API. You can get this by clicking on "Show CURL example" from an API profile
type: 'POST', // The HTTP Method
data: {}, // Additional parameters here
dataType: 'json',
success: function(data) { alert(JSON.stringify(data)); },
error: function(err) { alert(err); },
beforeSend: function(xhr) {
xhr.setRequestHeader("X-Mashape-Authorization", "YOUR-MASHAPE-KEY"); // Enter here your Mashape key
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment