Wrap HTTP content into HTTPS in Ajax request from Codepen
When trying to access mixed content with ajax in codepen, say:
function call_api_chuck () {
$.ajax({
url: "http://api.icndb.com/jokes/random",
jsonp: "callback",
type: "GET",
dataType: "jsonp",
success: function (data) {
$("#author").remove();
$("#quote").append(data["value"]["joke"]);
},
xhrFields: {
withCredentials: false
}
});
};
And you have other resources in your pen accessed via HTTPS, you get a Mixed-Content error.
Simply add https://crossorigin.me/ before your url and it will be successfully wrapped.
url: "https://crossorigin.me/http://api.icndb.com/jokes/random"Written by Esteban
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ajax
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#