基于XHR\script\Iframe编写远程脚本
来源:互联网 发布:mac海马玩模拟器卸载 编辑:程序博客网 时间:2024/05/30 05:40
dojo.xhr*函数:dojo.xhrGet , dojo.xhrPost , dojo.xhrPut , dojo.rawXhrPut , dojo.xhrDelete
带有一个叫做args的参数散列
function example1(){
dojo.xhrGet({
url:"demo/id1",
load:function(response){alert(response);},
error:function(error){alert(error.message);}
});
dojo.xhrGet({
url:"demo/id1",
handle:function(response){
if (response instanceOf Error){
alert("failed:"+response.message);
}
else{
alert("succeeded:"+response);
}
}
});
}
备注:
instanceof 运算符:
result = objectinstanceofclass
如果object 是 class 的一个实例,则 instanceof 运算符返回true。如果 object 不是指定类的一个实例,或者 object 是 null,则返回 false.
Ajax的一个示例:
如需获得来自服务器的响应,请使用 XMLHttpRequest 对象的 responseText 或 responseXML 属性。
html源码:
<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
var xmlhttp;
var txt,x,i;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
xmlDoc=xmlhttp.responseXML;
txt="";
x=xmlDoc.getElementsByTagName("title");
for (i=0;i<x.length;i++)
{
txt=txt + x[i].childNodes[0].nodeValue + "<br />";
}
document.getElementById("myDiv").innerHTML=txt;
}
}
xmlhttp.open("GET","/example/xmle/books.xml",true);
xmlhttp.send();
}
</script>
</head>
<body>
<h2>My Book Collection:</h2>
<div id="myDiv"></div>
<button type="button" onclick="loadXMLDoc()">获得我的图书收藏列表</button>
</body>
</html>
xml源码:
onreadystatechange 事件
存有 XMLHttpRequest 的状态。从 0 到 4 发生变化。
- 0: 请求未初始化
- 1: 服务器连接已建立
- 2: 请求已接收
- 3: 请求处理中
- 4: 请求已完成,且响应已就绪
200: "OK"
404: 未找到页面
- 基于XHR\script\Iframe编写远程脚本
- 使用Script.NET编写NSIS安装脚本
- 了解 JavaFX Script 编程语言 --第 2 课:编写脚本
- Android Monkey之script脚本--编写和运行
- script脚本
- 脚本script
- IFRAME高度进行自适应 javascript脚本编写【JAVASCRIP】
- 关于script,img,iframe等由js脚本发起的跨域
- xhr
- XHR
- XHR
- 基于JSVC编写Linux启动脚本
- 基于ubuntu编写的几个shell脚本
- 基于数组的shell脚本编写
- Monkeyrunner基于python编写脚本通用方法
- 基于iframe的CFS(Cross Frame Script)和Clickjacking(点击劫持)攻击
- ajax的实现,基于XHR的原理
- javascript 判断 iframe是否加载成功(该方法可自然延伸到判断script脚本是否加载成功)
- Android中Handler的使用
- 在64位Linux上安装Memcached
- eclipse插件安装不了的解决方法
- IIS6.0 应用程序池无法启动
- #Awk#join的参数说明
- 基于XHR\script\Iframe编写远程脚本
- 打开‘浏览文件“对话框
- hdu 2061
- COM中GUID和UUID、CLSID、IID
- Android实现页面自动循环切换【Gallery】
- 浏览器与服务器通信过程
- Java中时间加减的比较
- Json解析性能比较笔记(一)
- 推荐 C++图书三人谈