我的 jquery ajax 代码在我的本地服务器上运行良好。但是,它不适用于远程服务器 justhost.com。这让我发疯了。:( 有人可以指出我哪里出错了吗?
Merry Flowers是我网站的链接。当您打开 firebug 访问网站时,您将能够看到以下提到的错误。
当我尝试使用 firebug 进行调试时,出现以下 2 个错误:
我在以下行收到语法错误:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
我尝试了不同的文档类型,但仍然遇到相同的错误。
我在以下行收到“$ 未定义错误”:
$(document).ready(function(){
谷歌浏览器开发者工具的错误:
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
当我单击 chrome 开发人员工具的网络选项卡时,
jquery.js's type is text/html not application/javascript. While the other javascript files are of type application/javascript.
在按照 Lazerblade 要求进行所有更正后,cakephp 的原始 default.ctp 代码:
<!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">
© 2011 Merry Flowers Montessori | Designed by VRI Web
</div>
</div><!--div container finish-->
</body>
</html>
以下是修改后的default.ctp查看源码(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 & 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">
© 2011 Merry Flowers Montessori | Designed by VRI Web
</div>
</div><!--div container finish-->
</body>
</html>
顺便说一句,我正在使用 jquery 和 cakephp。谢谢你。