Search code examples
jqueryajaxjsonpmime

Ajax JSONP refuses to execute code because of MIME type


I'v been trying to make a script that checks reddit page and sends back titles of posts. I am able to use

$( "#foo" ).load( "https://www.reddit.com/r/csgobetting/search?q=flair%3Amatch&sort=new&restrict_sr=on&t=all&feature=legacy_search #siteTable .thing .title a:even" )

but I have to use chrome extension and I want to avoid it at all costs. (It gives me No 'Access-Control-Allow-Origin' header is present error in console)

other thing I tryed is

$.ajax({
    url: "https://www.reddit.com/r/csgobetting/search?q=flair%3Amatch&sort=old&restrict_sr=on&t=all&feature=legacy_search",
    jsonp: "callback",
    dataType: "jsonp",
    success: function(data){
        data=$(data).find('#siteTable > div.thing.id-t3_3m2ezw.linkflair.linkflair-match.odd.link.self > div.entry.unvoted > p.title > a ');
        $('#foo').append(  data );
    }
});

But it gives me error:

Refused to execute script from 'https://www.reddit.com/r/cs...' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

I'v looked on the internet for 3 hours but couldnt find anything that would help me.

Also this is not duplicate to this post as it didint help me.

My goal is to get page titles with links without using extensions or security disabling parameters.


Solution

  • Best way is cURL , download the HTML content of an URL then ECHO it to your javascript then get what you want :D , or do all of it in PHP with this great PLUGIN : https://code.google.com/p/phpquery/wiki/Selectors