jQuery.ajax() to grab a stringified version of a CSS File throws CORS error? -


on page, load css file cdn using line like:

<link rel="stylesheet" type="text/css" href="//cdnjs.cloudfare.com/whatever.css?abcdefg"> 

and css loads great. after page load, have javascript script loops through linked stylesheets , tries grab contents as string. so, using jquery ajax, code looks like:

//"links" array of linked stylesheets; each value link's href $.each(links, function(i, v) {    //assume first value in loops "//cdnjs.cloudfare.com/whatever.css?abcdefg"     $.ajax(v, {         mimetype: 'text/plain',         datatype: 'text',         complete: function(data) {             console.log(data.responsetext);         }     }) } 

i following cors error in console:

"xmlhttprequest cannot load //cdnjs.cloudfare.com/whatever.css?abcdefg. no 'access-control-allow-origin' header present on requested resource. origin 'http://stackoverflow.com' therefore not allowed access" 

how possible? if file missing cors header, wouldn't have been blocked when tried load css well? how did first cal work fine, cors failing? there anyway load css file text file without server's cooperation?

loading css file page used css via link element different requesting xhr , trying read content.

cors rightfully blocked doing that.

you can, however, parsed list of rules using javascript (i think firefox can picky @ blocks though).

start document.stylesheets value.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -