Skip to content

Instantly share code, notes, and snippets.

@danielalvarenga
Last active October 8, 2015 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielalvarenga/171aa289b31b6a02e4e8 to your computer and use it in GitHub Desktop.
Save danielalvarenga/171aa289b31b6a02e4e8 to your computer and use it in GitHub Desktop.
Ajax call with header params example.
Adicionar JQuery ao console
javascript:if(!window.jQuery||confirm('Overwrite\x20current\x20version?\x20v'+jQuery.fn.jquery))(function(d,s){s=d.createElement('script');s.src='https://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.js';(d.head||d.documentElement).appendChild(s)})(document);
Chamada AJAX
$.ajax({
headers: {
"Accept": "application/json; charset=utf-8",
"Content-Type": "application/json; charset=utf-8",
"Token": "123456789"
},
type: "POST",
url: "http://exemplo.com.br",
data: "{\"order\":{\"checkout_id\":\"teste1\",\"checkout_date\":\"2015-10-02 19:34:20\",\"type_checkout\":\"online\",\"bonus\":1660,\"cep\":\"05802140\",\"state\":\"SP\",\"items_attributes\":[{\"sku\":\"GRE8951\",\"bonus\":1660}]}}",
dataType: "json",
crossDomain: true,
success: function(data, textStatus, xhr){
console.log(xhr.status + " - " + JSON.stringify(data));
},
error: function(data, textStatus, xhr){
console.log(data.status + " - " + data.responseText);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment