Skip to content

jQuery

Use these code examples for bypassing CORS errors in jQuery requests with Corsfix CORS proxy.

$.ajax({
url: "https://proxy.corsfix.com/?https://api.example.com/data",
method: "GET",
success: function (response) {
console.log(response);
},
error: function (xhr) {
console.error(xhr);
},
});
$.ajax({
url: "https://proxy.corsfix.com/?https://api.example.com/data",
method: "GET",
headers: {
"x-corsfix-cache": "true",
},
success: function (response) {
console.log(response);
},
error: function (xhr) {
console.error(xhr);
},
});
$.ajax({
url: "https://proxy.corsfix.com/?https://api.example.com/data",
method: "POST",
contentType: "application/json",
data: JSON.stringify({
data: "mydata",
}),
success: function (response) {
console.log(response);
},
error: function (xhr) {
console.error(xhr);
},
});
$.ajax({
url:
"https://proxy.corsfix.com/?" +
"https://api.example.com/data?key={{SECRET_KEY}}",
method: "POST",
headers: {
Authorization: "Bearer {{SECRET_TOKEN}}",
},
contentType: "application/json",
data: JSON.stringify({
data: "mydata",
}),
success: function (response) {
console.log(response);
},
error: function (xhr) {
console.error(xhr);
},
});
$.ajax({
url: "https://proxy.corsfix.com/?https://api.example.com/data",
method: "GET",
headers: {
"x-corsfix-headers": JSON.stringify({
"User-Agent": "MyAgent/1.0",
}),
},
success: function (response) {
console.log(response);
},
error: function (xhr) {
console.error(xhr);
},
});