除了xhrGet,Dojo的XHR框架还包含xhrPost,rawXhrPost,xhrPut,rawXhrPut,xhrDelete.这几个函数与xhrGet类似,使用方法和参数都可以参考xhrGet.区别在于他们的HTTP请求类型,xhrPost发送的是Post请求,xhrPut发送的是Put请求,xhrDelete发生的是Delete请求。
下面我们看几个实例:
1、使用xhrGet请求文本资源
客户端--
[html]viewplaincopyprint?
01.<%@PageLanguage=“C#”AutoEventWireup=“true”CodeBehind=“HellodojoAjax.aspx.cs”
02.Inherits=“DojoTest.HellodojoAjax”%>
03.
04.<!DOCTYPEhtmlPUBLIC“-//W3C//DTDXHTML1.0Transitional//EN”“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
05.<htmlxmlns=“http://www.w3.org/1999/xhtml”>
06.<headrunat=“server”>
07.<title></title>
08.<scriptsrc=\'#\'" //ajax.googleapis.com/ajax/libs/dojo/1.7.2/dojo/dojo.js”type=“text/javascript”></script>
09.<scripttype=“text/javascript”>
10.
11.functionhelloWorld(){
12.dojo.xhrGet({
13.url:“Hellodojo.txt”,//请求的服务器资源url
14.handleAs:“text”,//返回的数据类型
15.load:function(response,ioArgs){alert(response);},//成功后回调函数
16.error:function(error,ioArgs){alert(error.message);}//出错时回调函数
17.});
18.}
19.
20.//绑定页面加载完成后的初始化函数
21.dojo.ready(helloWorld);
22.</script>
23.</head>
24.<body>
25.
26.</body>
27.<
<%@PageLanguage=“C#”AutoEventWireup=“true”CodeBehind=“HellodojoAjax.aspx.cs”
Inherits=“DojoTest.HellodojoAjax”%>
<!DOCTYPEhtmlPUBLIC“-//W3C//DTDXHTML1.0Transitional//EN”“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<htmlxmlns=“http://www.w3.org/1999/xhtml”>
<headrunat=“server”>
<title></title>
<scriptsrc=\'#\'" //ajax.googleapis.com/ajax/libs/dojo/1.7.2/dojo/dojo.js”type=“text/javascript”></script>
<scripttype=“text/javascript”>
functionhelloWorld(){
dojo.xhrGet({
url:“Hellodojo.txt”,//请求的服务器资源url
handleAs:“text”,//返回的数据类型
load:function(response,//成功后回调函数
error:function(error,ioArgs){alert(error.message);}//出错时回调函数
});
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。