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

AJAX Cross Domain Same Origin Policy limitation

摘自:http://www.ibm.com/developerworks/library/wa-aj-jsonp1/
AJAX Same-Origin Policy(SOP) limitation:
 AJAX prevents cross-domail invokation, there are several ways to by pass this limitation.
1. write a proxy on the server side. The SOP limitation only exists only on the javascript side.  While on the side, we can still invoke the other domail url such as via HttpClient
2. iFrame ( not sure )
3. JSONP(JSON with Padding)
the same-origin policy doesn't prevent the insertion of dynamic script elements into the document. That is, you could dynamically insert JavaScript from different domains, carrying JSON data in them.
<mce:script type="text/javascript"><!--
// This is our function to be called with JSON data
function showPrice(data) {
alert("Symbol: " + data.symbol + ", Price: " + data.price);
}
var url = “ticker.js”; // URL of the external script
// this shows dynamic script insertion
var script = document.createElement('script');
script.setAttribute('src', url);
// load the script
document.getElementsByTagName('head')[0].appendChild(script);
// --></mce:script>
Note that, in order to do this, you must have a callback function already defined in the Web page at the time of insertion.
Beginning with version 1.2, jQuery has had native support for JSONP calls. You can load JSON data located on another domain if you specify a JSONP callback, which can be done using the following syntax: url?callback=?.
AJAX invoke:
jQuery.getJSON("http://www.yourdomain.com/jsonp/ticker?symbol=IBM&callback=?",
function(data) {
alert("Symbol: " + data.symbol + ", Price: " + data.price);
});

Another domain generates json data and returned to client side with callback function.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String jsonData = getDataAsJson(req.getParameter("symbol"));
String output = req.getParameter("


相关文档:

Ajax的post方法的使用

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

流行的AJAX框架对比:jQuery,Mootools,Dojo,Ext JS

AJAX
是web2.0
的基石,现在网上流行几种开源的AJAX框架,比
如:jQuery,Mootools,Dojo,Ext JS等等,那么我们到底在什么情况下该使用那个框架?以下是一组摘抄的数据:
Ajaxian在2007年底对Ajax工具进行了调查,部分调查结果见下表(其中数字为调查者使用该工具的百分比,详细的请参见网页):http://ajaxian.com/archi ......

ajax入门

描述:Ajax基础 在进行Ajax开发以前,我们必须先对一些基本的知识进行了解。虽然Ajax.NET已经将Ajax实现细节封装起来,并大大简化
Ajax基础
在 进行Ajax开发以前,我们必须先对一些基本的知识进行了解。虽然Ajax.NET已经将Ajax实现细节封装起来,并大大简化了我们的操作,但是了解基 本的Ajax实现方式对于帮助我们在开发中 ......

简单的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");
......

struts2+jquery+ajax异步提交

struts2版本:struts-2.1.8.1
异常:java.lang.NoClassDefFoundError: com/opensymphony/xwork2/util/TextUtils
原因:jsonplugin-0.34.jar 配合 struts2-core-2.1.8.1.jar 使用的情况下报的异常,但以前的项目中jsonplugin-0.34.jar 配合 struts2-core-2.1.6.jar 使用不会出现这样的异常
解决方法:去掉jsonplugin-0.34 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号