jquery ajax:doctype语法错误,$是远程服务器上未定义的错误 [英] jquery ajax: doctype syntax error and $ is not defined error on remote server

查看:297
本文介绍了jquery ajax:doctype语法错误,$是远程服务器上未定义的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的jquery ajax代码在我的本地服务器上正常工作。但是,它不工作在远程服务器justhost.com。这是推动我坚果。 (有人可以指出我出错的地方吗?

My jquery ajax code is working fine on my local server. However, it is not working on the remote server justhost.com. This is driving me nuts. :( Can someone point out on where i'm going wrong?

Merry Flowers 是到我的网站的链接。当你访问带有firebug的网站时,u将能够看到下面提到的错误。

Merry Flowers is the link to my website. When u go to the website with firebug on, u will be able to see the below mentioned errors.

当我尝试用firebug调试时,我得到以下2个错误:

When I try to debug with firebug, i'm getting the following 2 errors:

我在下面一行得到语法错误:

i'm getting a syntax error on the following line:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

我尝试使用不同的doctypes仍然收到相同的错误。

I tried with different doctypes and I was still getting the same errors.

我在下面的行中得到$未定义错误:

i'm getting "$ is not defined error" on the following line:

$(document).ready(function(){

Google chrome开发者工具的错误:

Google chrome developer tool's errors:

    Resource interpreted as Script but transferred with MIME type text/html: "http://www.merryflowers.com/js/jquery.js".
jquery.js:1Uncaught SyntaxError: Unexpected token <
home:8Uncaught ReferenceError: $ is not defined

开发者工具

jquery.js's type is text/html not application/javascript. While the other javascript files are of type application/javascript.

cakephp的原始default.ctp代码,根据Lazerblade的要求进行所有更正:

cakephp's original default.ctp code after all the corrections as requested by Lazerblade:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 

Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<?php
 echo $this->Html->charset();
 ?>
<title>
    <?php  __('Merry Flowers Montessori'); ?>
    <?php echo $title_for_layout; ?>
</title>
<?php
    //echo $this->Html->meta('icon');
    echo $this->Html->css('cake.generic');  //link to cake.generic.css will be 

placed in $scripts_for_layout
        echo $this->Html->css('navbar.css'); 
        echo $this->Html->script('jquery.js'); //Include jquery library
/*      echo $this->Html->script('swfobject.js');
*/

    echo $this->Session->flash();
    echo $this->Session->flash('email');
    echo $scripts_for_layout;
?>
<script type="text/javascript">
   //var j=jQuery.noConflict();
  $(document).ready(function(){
      $("#MerryParentEmail").change(function(){
        //txt=$("#MerryParentEmail").val();
        email_id=$("#MerryParentEmail").serialize();
        //alert(txt);
        $.post("/students/get_parent_info",email_id,function(result_str){
        result_array=result_str.split('*****');
          $("#MerryParentInitial").val(result_array[0]);
          $("#MerryParentName").val(result_array[1]); 
          $("#MerryParentLandline").val(result_array[2]);
          $("#MerryParentMobile").val(result_array[3]); 
          $("#MerryParentAddress").val(result_array[4]);
          $("#MerryParentStateId").val(result_array[5]);
          state=result_array[5];
          txt_str="state_id="+state;
          $.get("/students/getcities",txt_str,function(result){
            $("#MerryParentCityId").html(result).show();
            $("#MerryParentCityId").val(result_array[6]);
          });
          $("#MerryParentPostalCode").val(result_array[7]);
        });
      });

       $("#MerryParentStateId").change(function(){
        state=$(this).val();
        txt_str="state_id="+state;
        $.get("/students/getcities",txt_str,function(result){
            $("#MerryParentCityId").html(result).show();
        });
       });
 });
 </script>
</head>
<body>

<div id="container">
    <div id="header">
            <?php 
               echo $this->element('logo');
               echo $this->element('navbar');
              ?>
    </div> <!-- finish div header -->
    <div id="content">
        <div>
            <div id="content1">
            <?php echo $content_for_layout; ?>
            </div>
            <div id="content2">
                <?php 
                       echo $this->Html->link($this->Html->image("admission_open.gif",array("alt"=>"admissions")),
                                "/students/add",array('escape'=>false));  //if escape is false, admission_open.gif 

displays, otherwise only link <img src="/merry_flowers/img/admission_open.gif" alt="admissions"/> displays.
                          echo $this->Html->image("contact_us.gif", $options=array()); 
                    ?>  
                </div> 
            </div>
        </div>  <!--finish div content-->
        <div id="footer"> 
            &copy;  2011 Merry Flowers Montessori | Designed by VRI Web
        </div>
   </div><!--div container finish-->
</body>
</html>

以下是所有更正后的default.ctp视图源代码(cakephp )。

The following is the view source code of default.ctp after all the corrections (the layout page in cakephp).

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 

Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   <title>
        Merry Flowers Montessori        Home    </title>
    <link rel="stylesheet" type="text/css" href="/css/cake.generic.css" /><link rel="stylesheet" type="text/css" href="/css/navbar.css" /><script type="text/javascript" src="/js/jquery.js"></script><script type="text/javascript" src="/js/swfobject.js"></script>   <script type="text/javascript">
       //var j=jQuery.noConflict();
      $(document).ready(function(){
          $("#MerryParentEmail").change(function(){

        //txt=$("#MerryParentEmail").val();
        email_id=$("#MerryParentEmail").serialize();
        //alert(txt);
        $.post("/students/get_parent_info",email_id,function(result_str){
        result_array=result_str.split('*****');
          $("#MerryParentInitial").val(result_array[0]);
          $("#MerryParentName").val(result_array[1]); 
          $("#MerryParentLandline").val(result_array[2]);
          $("#MerryParentMobile").val(result_array[3]); 
          $("#MerryParentAddress").val(result_array[4]);
          $("#MerryParentStateId").val(result_array[5]);
          state=result_array[5];
          txt_str="state_id="+state;
          $.get("/students/getcities",txt_str,function(result){
            $("#MerryParentCityId").html(result).show();
            $("#MerryParentCityId").val(result_array[6]);
          });
          $("#MerryParentPostalCode").val(result_array[7]);
        });
      });

       $("#MerryParentStateId").change(function(){
        state=$(this).val();


txt_str="state_id="+state;
            $.get("/students/getcities",txt_str,function(result){
                $("#MerryParentCityId").html(result).show();
            });
           });
     });
     </script>
</head>

<body>
<div id="container">

    <div id="header">
            <div>
<div style="float:left; width:98%; background-color:#ffffff;">
<img src="/img/logo.png" alt="" />  </div>
<div style="float:right; width:5%; top:100%; right:10%;">
<a href="/pages/home">Home</a>  </div>

    </div><div id="menu">

    <ul id="nav">

<!--        <li><a href="/pages/home">Home</a></li>
-->         <li><a href="#">Our Program</a><ul>

        <li><a href="/pages/preschool">Preschool</a></li>
        <li><a href="/pages/kindergarten">Kindergarten</a></li>
        <li><a href="/pages/summer_camp">Summer Camp</a></li>
        </ul>
        </li>
        <li><a href="#">About Us</a><ul>

        <li><a href="/pages/about_us">Merry Flowers</a></li>
        <li><a href="/pages/tour_our_school">Tour Our School</a></li>
        <li><a href="/pages/contact_us">Contact Us</a></li>
        </ul>
        </li>

        <li><a href="#">My Child</a><ul>
        <li><a href="/merry_parents/register">Report Card</a></li>

        </ul>
        </li>

        <li><a href="#">Events</a><ul>
        <li><a href="#">News &amp; Events</a>               <ul>
                <li><a href="/pages/sports_day">Sports Day</a></li>
                <li><a href="/pages/annual_day">Annual Day</a></li>

            </ul>
        </li>

        <li><a href="/pages/list_of_holidays">List of Holidays</a></li>
        </ul>
        </li>
        <li><a href="#">FAQ</a><ul>
        <li><a href="/pages/faq">FAQ</a></li>

        <li><a href="/feedbacks/add">Feedback</a></li>
        <li><a href="/forum/home">Discussion</a></li>
        </ul>
        </li>
        <li><a href="#">Admissions</a><ul>
        <li><a href="/students/add">Enroll Now</a></li>
        </ul>

        </li>
    </ul><!--finish ul nav-->
   </div> <!--finish div menu-->        </div> <!-- finish div header -->
    <div id="content">
        <div>
            <div id="content1">
            <script type="text/javascript">
//<![CDATA[
swfobject.embedSWF("/main_ani.swf", "content1", "530", "300", "9.0.0",
            "", {}, {wmode : "opaque"}, {});
//]]>
</script>               </div>

                <div id="content2">
                    <a href="/students/add"><img src="/img/admission_open.gif" alt="admissions" /></a><img src="/img/contact_us.gif" alt="" />  
                </div> 
            </div>

    </div>  <!--finish div content-->
    <div id="footer"> 
        &copy;  2011 Merry Flowers Montessori | Designed by VRI Web
    </div>


 </div><!--div container finish-->
</body>

</html>

顺便说一句,我使用jquery和cakephp。谢谢。

By the way, i'm using jquery with cakephp. Thank you.

推荐答案

再次检查。问题不是jQuery文件本身,它的方式,它被添加,可能的.htaccess文件有冲突,或路径设置错误。它试图加载错误页面。查看Chrome开发者工具中的预览和响应,特别是加载jQuery.js时的响应。当您请求jQuery文件时,您正在加载网站页面。我需要看到更多的实际代码,而不是视图源,以找出确切的问题,但结果是jQuery不加载...

Check again. The issue isn't the jQuery file itself, it's in the way it's being added, possibly the .htaccess file has a conflict, or the path is set up wrong. It's trying to load an error page. Look at the preview and response in Chrome Developer Tools, specifically the response when it loads jQuery.js. You're loading your website page when you request the jQuery file. I'd need to see more of the actual code, not the view source, in order to figure out the exact issue, but the result is that jQuery isn't loading...

编辑:检查您的jQuery文件是否确实在/ js /文件夹,并且它的命名正好jquery.js,而不是jquery.latest.min.js或这些行的东西。文件名是区分大小写的,所以如果是jQuery.js(注意大写字母Q),你需要重命名或更改代码。还打开jQuery文件,并确保它不是空的(通常下载jQuery需要打开文件在浏览器中的纯文本,复制所有,粘贴到文件,并保存该文件)。

Check that your jQuery file is indeed in the /js/ folder and that it is named exactly jquery.js, not jquery.latest.min.js or something along those lines. Filenames are case sensitive, so if it's jQuery.js (note the capital Q), you'll need to rename or change your code. Also open the jQuery file and make sure it's not empty (often "downloading" jQuery requires opening the file in your browser as plain text, copying all, pasting into a file, and saving that file).

EDIT2:如果这是在本地工作,而不是远程工作,有2种可能的原因。您在公用文件夹中的.htaccess文件中缺少重写条件,或者在您的配置文件中有/ localhost / apache httpd.config或.htaccess文件,或者可能在config.php文件中(从您的公用文件夹中的index.php调用)。

If this is working locally but not remotely, there are 2 possible reasons. You're either missing the rewrite conditions in your .htaccess file in your public folder, or you have /localhost/ in one of your config files, either apache httpd.config or an .htaccess file, or possibly in your config.php file (called from index.php in your public folder).

Options -Indexes
RewriteEngine on
#
# Redirect all non-image and non-file requests to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?url=$1 [PT,L]

.htaccess在您的公用文件夹中,重定向其路径不在您的公用文件夹中的所有请求,以转到您的索引文件。

Example of .htaccess in your public folder, to redirect all requests whose path is not in your public folder to go to your index file instead.

这篇关于jquery ajax:doctype语法错误,$是远程服务器上未定义的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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