易截截图软件、单文件、免安装、纯绿色、仅160KB

Ajax跨域问题解决方案

由于安全问题的考虑,Ajax(xmlhttprequest)默认是不支持跨域调用的。比如在www.cadal.com去请求www.test.cadal.com的数据,都是不行的。
解决方案有很多,总结如下:
参考:
1.利用<script>标签
Difficult to know when the content is available, no standard methodology, can be considered a "security risk".
script设置Url后自动会执行
example
远端:
var data=123;
客户端:
<html>
<body>
<mce:script id="test"></mce:script>
<input type="button" id="button" value="获取" onclick="get('http://test.cadal.com/demo/test.asp');">
<mce:script type="text/javascript"><!--

function get(url)
{
document.getElementById("test").src=url;
alert(data);
}
// --></mce:script>
</body>
</html>
2.代理
Local proxy:
Needs infrastructure (can't run a serverless client) and you get double-taxed on bandwidth and latency (remote - proxy - client).
利用如动态网页ASP JSP PHP等进行代理,进行中转,缺点显而易见。
3.frame方法
在同一个域下的各个子域之间(非完全跨域),如果设置了document.domain,那么是可以相互之间调用js的。。利用这一点,可以在test.zzsky.cn下面放上一个页面,这个页面可以完成用ajax获取同一个子域www.test.cadal.com的数据,而在 www.cadal.com下框架这个页,这样就可以操纵被框架页来获取数据了。
example
远端frame:
<html>
<head>
<mce:script type="text/javascript" src="http://www.cadal.com/demo/ajax-cross-domain/Ajax.js" mce_src="http://www.cadal.com/demo/ajax-cross-domain/Ajax.js"></mce:script>
<mce:script type="text/javascript"><!--

document.domain="cadal.com";
// --></mce:script>
</head>
<body>
</body>
</html>
客户端:
<html>
<head>
<mce:script type="text/javascript"><!--

document.domain="cadal.com";
// --></mce:script>
<body>
<iframe src="http://test.cadal.com/demo/iframe.htm" mce_src="http://te


相关文档:

Ajax的post方法的使用

刚开始学Ajax,看到很多网上的代码都用Get方法提交参数,Tomcat默认ISO编码实在是让人头痛,对付乱码我都是用过滤器做字符编码过滤的,Get方法过滤器监听不到,所以我一直喜欢使用Post方法,下面对Ajax Get和Post方法做一对比
GET:
view plaincopy to clipboardprint?
<mce:script type="text/javascript"><!- ......

jQuery Ajax 回顾

     在本节我准备只写上关于Ajax的说明,多数来自jQuery的帮助文档,所以不要放在首页。因为我觉得首页应该是要花费了时间和心思的作品。代码演示和jQuery Ajax 一些新的,将在下一次有空时讲述,这里就不讲了。时间已经0晨了。如果你举得有什么jQuery的疑问或者觉得Ajax该讲述那些内容的都可以跟我留 ......

Ajax 的状态介绍

在《Pragmatic Ajax A Web 2.0 Primer 》中偶然看到对readyStae状态的介绍,感觉这个介绍很实在,摘译如下:
0: (Uninitialized) the send( ) method has not yet been invoked.
1: (Loading) the send( ) method has been invoked, request in progress.
2: (Loaded) the send( ) method has completed, entire respons ......

asp.net在用ajax的时候如何弹出对话框


<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
    <asp:updatepanel ID="UP" runat="server">
      <ContentTemplate>
......

简单的AJAX获取数据库表数据

A.aspx页面放一个dropdownlist,在A.aspx.cs添加: this.drpSchool.Attributes.Add("onchange", "load(this.options[this.selectedIndex].value)");
在A.aspx页面添加如下脚本:
function load(state){
var oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");
var oDoc = new ActiveXObject("MSXML2.DOMDocument");
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号