IT技术精粹[JiShuBu.Com]-倾力打造一流IT技术平台!
登录
注册
设为首页
加入收藏
网站首页
IT风向标
网站优化
Html
CSS
JavaScript
ASP
Php/Mysql
Flash
Ajax
源码下载
精美桌面
供求信息
超稳定100M虚拟主机只要100元,还送50M邮箱!
文字广告招商中...
会员注册
|
用户登录
|
我要投稿
信息订阅
'AjaxPro'未定义错误的原因&javascript顺序执行&AjaxPro机制
您现在正在浏览:
首页
>
Ajax
>
'AjaxPro'未定义错误的原因&javascript顺序执行&AjaxPro机制
作者: 发布时间:2008-01-28 17:56:40 来源:
先从
javascript的执行方式
说起吧!我用C#比较熟,在C#里面任何一个变量或函数的位置是无关紧要的,比如说下面
public void add()
{
i++;
}
public void run()
{
add();
}
int i=0;
和下面的方法没有区别
public void add()
{
i++;
}
int i=0;
public void run()
{
add();
}
但是在javascript里面就不行了,如果你这么写
function add()
{
i++;
}
add();
var i=0;
这时候就会出错!因为在add里面的i尚未定义(undefined)!所以说javascript的执行方式为顺序执行(暂且不说C#到底是不是顺序执行!)
再来说说
AjaxPro的机制
,
首先我们说说AjaxPro.Utility.RegisterTypeForAjax到底做了什么?
Ajax的基本原理其实很简单,就是XmlHttpRequest通道加异步。AjaxPro起到就是
框架
和包装器的作用,一般我们在on_load里面用AjaxPro.Utility.RegisterTypeForAjax实现这些(当然这里面AjaxPro.AjaxMethod()起到配合的作用),到底做了什么呢?服务端就不说了(我估计用到了缓存方法),在客户端aspx(html)
页面
里紧跟<form name="form1" method="post" action="Default3.aspx" id="form1">隔着VIEWSTATE生成了下面
注册
脚本
<script type="text/javascript" src="/
Web
/
ajax
pro/prototype.ashx"></script>
<script type="text/javascript" src="/Web/ajaxpro/core.ashx"></script>
<script type="text/javascript" src="/Web/ajaxpro/converter.ashx"></script>
<script type="text/javascript" src="/Web/ajaxpro/Default3,App_Web_wvuzlcxq.ashx"></script>
上面这些javascript就是AjaxPro实现了Ajax框架和通道的包,其中
<script type="text/javascript" src="/Web/ajaxpro/core.ashx"></script>
里面有
AjaxPro.onLoading
的声明!
下面该说
出现'AjaxPro'未定义错误的原因
了!
在我这里出现这种错误的情况是这样的
Default3.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!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 runat="server">
<title>无标题页</title>
<script type="text/javascript">
function get(r)
{
document.getElementById("m").innerText=(r.value);
}
AjaxPro.onLoading=function(b){
document.getElementById("loading").style.display = b ? "block" : "none";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<
div
>
<div id="loading" style="display:none;">正在获取
服务器
端时间
</div>
<div id="m" style="display:block;">
</div>
<input id="but" type="button" value="button" />
</div>
</form>
</body>
</html>
Default3.aspx.cs
。。。
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(Default3));
}
[AjaxPro.AjaxMethod]
//[AjaxPro.AjaxServerCache(10)]
public string gett()
{
System.Threading.Thread.Sleep(2000);
return DateTime.Now.ToString();
}
}
你可以看到我把AjaxPro.onLoading放到了<form id="form1" runat="server">上面,也就是说源文件里放到了
<script type="text/javascript" src="/Web/ajaxpro/prototype.ashx"></script>
<script type="text/javascript" src="/Web/ajaxpro/core.ashx"></script>
<script type="text/javascript" src="/Web/ajaxpro/converter.ashx"></script>
<script type="text/javascript" src="/Web/ajaxpro/Default3,App_Web_wvuzlcxq.ashx"></script>
的上面,由于javascript是顺序执行的,所以就出现了'AjaxPro'未定义错误!
我把html文件改成下面
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!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 runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<script type="text/javascript">
function get(r)
{
document.getElementById("m").innerText=(r.value);
}
AjaxPro.onLoading=function(b){
document.getElementById("loading").style.display = b ? "block" : "none";
}
</script >
<div>
<div id="loading" style="display:none;">正在获取服务器端时间
</div>
<div id="m" style="display:block;">
</div>
<input id="but" type="button" value="button" />
</div>
</form>
</body>
</html>
就行了!
【
评论
】【
加入收藏夹
】【
大
中
小
】【
打印
】【
关闭
】
※
相关信息
无相关信息
发表评论
查看评论
用户名:
密码:
验证码:
匿名发表
[
注册帐号
]
[
控制面板
]
[
用户登陆
]
[
修改资料
]
[
用户收藏
]
[
我的状态
]
[
退出登陆
]
文章搜索
标题
作者
[
添加文章
] [
管理文章
]
最新技术文档
·
十天学会PHP之基础知识
·
十天学会PHP之流程控制
·
十天学会PHP之构建数据库
·
十天学会PHP之连接数据库
·
echo和print 的区别
·
PHP生成随机字符串
·
PHP取得文件后缀
·
正则表达式经验谈
·
PHP的Cookie技术介绍
·
PHP数组排序
技术文档排行榜
·
天气预报小偷,根据IP自动判断地址
·
超经典计算机使用问题105答
·
'AjaxPro'未定义错误的原因&javascript顺
·
[初学者必读]网页制作之HTML基础知识
·
DIV&CSS打造自动伸展三栏复合布局
·
CSS网页布局入门教程:下拉及多级弹出式菜单
·
阿里妈妈广告的投放技巧
·
谁是网页浏览器引擎速度真正王者
·
JavaScript:世界上误解最深的语言
·
几种常用禁止修改输入框的方法