简体   繁体   中英

JavaScript file stopped working on the last Chrome version

We have an old page. Recently Google Chrome (and other last version browsers) stopped showing menu , but if I hit "refresh", than Inspect Tool shows the following error:

Resource interpreted as Script but transferred with MIME type text/html: ".../menu.js.php"

What could be the solution for this problem, or the problem is actually elsewhere?

Its because the header content type is not being set correctly by the server:

Content-Type: application/javascript

To clarify, your server should set the correct http header on the response to reflect the content type.

I guess in your page you have a script tag with type="text/javascript" but Chrome is saying the server is not identifying the content as javascript.

the Content-Type this is not the problem.

the problem is elsewhere. A problem that I see is with fancybox:

jQuery from version 1.9 has removed most if not all of the depreciated methods.

$.browser was one of them. Fancybox relies on $.browser, so you can't use jQuery 1.9 or maior and your version of fancybox without the migrate plugin installed.

You can downgrade jQuery to a version < 1.9 or upgrade fancybox to version 2 or include the jquery migrate plugin .

Because the Javascript files are actually PHP files, the server transfers the file as text/html . I did not find this out myself. I took it from SCRIPTONITE's answer

To set a header in PHP, you can use the header() function. You should always set the headers as early as possible to avoid errors. You may only set headers if you have not yet sent anything to the output. No echo, not HTML, nothing. From the manual:

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.

To set the header for a Javascript file, use this line:

header("Content-Type: application/javascript");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM