Chrome says “Resource interpreted as script but tr

2018-12-31 09:50发布

In FF and all, my javascript works fine. But in Chrome it gives this message:

Resource interpreted as script but transferred with MIME type text/plain.

I have checked all the script tags and they all have the MIME type="text/javascript". It even says so with jquery and jquery ui. What is wrong with Chrome?

What's the problem and the fix for this? Is it something I have to change in the 'options' of the browser or is it from the server, or do I have to tweak my code?

20条回答
素衣白纱
2楼-- · 2018-12-31 10:21

I had this problem and I figured out how to fix it.

It happens when the style (CSS) file is in a different encoding from the PHP file that references the .css file

For example, using jQuery.js in Unix encoding and using index.php in UTF-8 will cause this problem so you have to make them both UTF-8 or any other encoding as long as it the same.

查看更多
看风景的人
3楼-- · 2018-12-31 10:24

I was having the same issue when trying to change a background images in a array through javascript (jQuery in this case).

Anyway.

Instead of this:

m.setStyle('background-image','url(/templates/site/images/style5/'+backgs[i]+')')

do this:

eval("m.setStyle('background-image','url(/templates/site/images/style5/'+backgs[i]+')')");

Chrome javascript gets screwed when trying to parse a variable inside an element structured with ' . In my case it stopped just before the image array being inserted. Instead of parsing the image url + image name (inside the array), it was parsing just the image url.

You probably need to search inside the code and see where it happens. FF, IE and all other don't have this problem.

查看更多
登录 后发表回答