$ {document).ready(function()无法正常工作 [英] $(document).ready(function() is not working

查看:149
本文介绍了$ {document).ready(function()无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jquery从solr服务器获取json对象.当我使用Tomcat运行html文件时,可以很好地运行它,但是当我将其嵌入在weblogic上运行的项目中时,会出现以下错误:(通过Firebug进行调试)

I am using Jquery for getting a json object from a solr server. When I run my html file with Tomcat it is runns fine but when I embed it with my project which is running on weblogic it gets this error: (debugging done through firebug)

$ is not defined
$(document).ready(function(){  

当我将其嵌入到项目中时为什么会出现此错误?

Why do I get this error when I embed it in my project?

这是我的<head>标记的内容,这就是我包含jquery.js的方式:

This is the contents of my <head> tag, It is how I include jquery.js:

<head>
  <title>Search Result  </title>
  <style>
    img{ height: 150px; float: left; border: 3;}
    div{font-size:10pt; margin-right:150px;
    margin-left:150px; }
  </style>

  <script type="text/javascript" src="jquery-1.6.1.js"></script>
  <script type="text/javascript">
    $(document).ready(function(){       //Error happens here, $ is not defined.

    });
  </script>
</head>

推荐答案

您是否在head部分中加载了jQuery?您加载正确吗?

Did you load jQuery in head section? Did you load it correctly?

<head>
   <script src="scripts/jquery.js"></script>
   ...
</head>

此代码假定jquery.jsscripts目录中. (您可以根据需要更改文件名)

This code assumes jquery.js is in scripts directory. (You can change file name if you like)

您还可以使用Google托管的jQuery :

You can also use jQuery as hosted by Google:

<head>
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
   ...
</head>

根据您的评论:

显然,您的Web服务器未配置为在请求/webProject/jquery-1.6.1.js时返回jQuery-1.6.1.js.可能有许多原因,例如错误的文件名,文件夹名,路由设置等.您需要创建另一个问题并更详细地描述404(例如本地文件名,操作系统,Web服务器名和设置).

As per your comment:

Apparently, your web server is not configured to return jQuery-1.6.1.js on requesting /webProject/jquery-1.6.1.js. There may be numerous reasons for this, such as wrong file name, folder name, routing settings, etc. You need to create another question and describe your 404 in greater details (such as local file name, operation system, webserver name and settings).

同样,您可以使用Google提供的jQuery(见上文),但是您仍然可能想找出为什么某些本地文件没有按要求提供的原因.

Again, you can use jQuery as provided by Google (see above), however you still might want to find out why some local files don't get served on request.

这篇关于$ {document).ready(function()无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆