简体   繁体   English

我的浏览器不认为我的Javascript是... Javascript?

[英]My browser doesn't think my Javascript is … Javascript?

HTML: HTML:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="/js/grabber.js" type="text/javascript"></script>
<script type="text/javascript">
        $(document).ready(function() {
            $('#search-js').submit(function() {
                var username = $("#bar-js").val();
                var result = grab(username);
                alert(result);
                $(".contents").html(result["twitter"]);
            });
        });
</script>

js/grabber.js: JS / grabber.js:

function grab(username) {
    //var results = {};

    // run all the things
    //results["twitter"] = check_twitter(username);

    // return your (huge) map
    //return results;
    return "stuff";
}

When I trigger the function, nothing happens. 当我触发该功能时,没有任何反应。 If I take the code inside grabber.js and embed it into the page, it works. 如果我将代码置于grabber.js并将其嵌入页面中,则grabber.js When I view the source with Chrome and click on the js/grabber.js link (in the HTML), Chrome tries to download the file instead of display it. 当我使用Chrome查看来源并点击js/grabber.js链接(在HTML中)时,Chrome会尝试下载该文件而不是显示该文件。 If I click on Google's jQuery link, it gets displayed. 如果我点击谷歌的jQuery链接,它会显示出来。

I'm new to the javascript world, but I've been at this for a while and can't seem to figure it out. 我是javascript世界的新手,但我已经有一段时间了,似乎无法弄明白。

EDIT: 编辑:

Chrome developer tools is giving me this: Chrome开发者工具给了我这个:

Resource interpreted as Script but transferred with MIME type text/x-js: "http://0.0.0.0:8000/js/grabber.js".

I'm using Python's SimpleHTTPServer to create a temporary server for quick development. 我正在使用Python的SimpleHTTPServer来创建一个临时服务器以便快速开发。 Could that be the issue? 这可能是问题吗?

I think for some reason your server is not setting the correct mime-type for .js files, try adding this to your .htaccess: 我认为由于某种原因,您的服务器没有为.js文件设置正确的mime类型,请尝试将其添加到.htaccess:

AddType text/javascript .js

Or maybe: 或者可能:

AddType application/x-javascript .js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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