jQuery
Use these code examples for bypassing CORS errors in jQuery requests with Corsfix CORS proxy.
GET Request
Section titled “GET Request”$.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); },});
Cached Response
Section titled “Cached Response”$.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); },});
POST Request
Section titled “POST Request”$.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); },});
Using Secrets
Section titled “Using Secrets”$.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); },});
Header Override
Section titled “Header Override”$.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); },});