Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery .get for non https, in a userscript

I made a script on my website that accesses a table on a different website. However, the other website is HTTP so chrome is telling me "This request has been blocked; the content must be served over HTTPS."

$.get('http://www.kanjidamage.com/kanji', null, function searchKD () { /*function*/ });

So what I'm asking is: how can I access elements on a different website even if it's not HTTPS.


1 Answers

You have this tagged as tampermonkey. If that is the case, use it.

Tampermonkey allows one to bypass "mixed active content" restrictions by using GM_xmlhttpRequestDoc.

So this complete Greasemonkey/Tampermonkey script works fine:

// ==UserScript==
// @name     _Mixed content AJAX
// @match    https://stackoverflow.com/questions/44620859/*
// @require  http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @grant    GM_xmlhttpRequest
// @connect  kanjidamage.com
// ==/UserScript==

GM_xmlhttpRequest ( {
    method: "GET",
    url: "http://www.kanjidamage.com/kanji",
    onload: function (response) {
        console.log (response.responseText);
    }
} );
like image 50
Brock Adams Avatar answered Oct 16 '25 16:10

Brock Adams