Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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
}
});
@chrisseldo

This comment has been minimized.

Show comment Hide comment
@chrisseldo

chrisseldo Mar 26, 2015

Thanks for this! By the way, the second "t" in your "dataType" parameter is lowercase.

Thanks for this! By the way, the second "t" in your "dataType" parameter is lowercase.

@preetparm

This comment has been minimized.

Show comment Hide comment
@preetparm

preetparm Jul 30, 2015

i am trying to this example but browser gives cross domain blocked error:
here is code.any suggestion please

$.ajax({
url: 'https://montanaflynn-dictionary.p.mashape.com/define', // The URL to the API. You can get this by clicking on "Show CURL example" from an API profile
type: 'GET', // The HTTP Method
data: {
'word':'irony'
}, // Additional parameters here
datatype: 'json',
success: function(data) { alert(JSON.stringify(data)); },
error: function(err) { console.log(err); },
beforeSend: function(xhr) {
xhr.setRequestHeader("X-Mashape-Authorization", "K1DagFUxxxxxxxxxxxxx"); // Enter here your Mashape key
}
});

i am trying to this example but browser gives cross domain blocked error:
here is code.any suggestion please

$.ajax({
url: 'https://montanaflynn-dictionary.p.mashape.com/define', // The URL to the API. You can get this by clicking on "Show CURL example" from an API profile
type: 'GET', // The HTTP Method
data: {
'word':'irony'
}, // Additional parameters here
datatype: 'json',
success: function(data) { alert(JSON.stringify(data)); },
error: function(err) { console.log(err); },
beforeSend: function(xhr) {
xhr.setRequestHeader("X-Mashape-Authorization", "K1DagFUxxxxxxxxxxxxx"); // Enter here your Mashape key
}
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment