跨域相关的文章老早写过几篇:
jquery url检测遇到的jquery跨域问题及JSONP的使用
本文是对第一篇的实例补充。
js脚本
$.getJSON ('http://sjolzy.cn/?callback=? &a=1&b=2', function(data) {
if (typeof(data) == 'object') {
$.each(data,function(i,j){
// ...
});
}
});
服务端代码
跨域相关的文章老早写过几篇:
jquery url检测遇到的jquery跨域问题及JSONP的使用
本文是对第一篇的实例补充。
js脚本
$.getJSON ('http://sjolzy.cn/?callback=? &a=1&b=2', function(data) {
if (typeof(data) == 'object') {
$.each(data,function(i,j){
// ...
});
}
});
服务端代码
先提下关于jQuery的$.Ajax 的async的作用,
官方的解释是
async Boolean Default: true
By default, all requests are sent asynchronous (e.g. this is set to true by default). If you need synchronous requests, set this option to false. Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active.
async默认是true, 即为异步方式, $.Ajax执行后, 会继续执行ajax后面的脚步, 直到服务器端返回数据后, 触发$.Ajax里的success方法. 这时候执行的是两个线程.
我的出现闪屏的情况是:
$.ajax({
type: "post",
url: "index.php",
data: { },
async:false,
[代码] [JavaScript]代码
var Ajax={};
Ajax._xmlHttp = function(){ return new (window.ActiveXObject||window.XMLHttpRequest)("Microsoft.XMLHTTP");}
Ajax._AddEventToXHP = function(xhp,fun,isxml){
xhp.onreadystatechange=function(){
if(xhp.readyState==4&&xhp.status==200)
fun(isxml?xhp.responseXML:xhp.responseText);
}
}
Ajax.get=function(url,fun,isxml,bool){
var _xhp = this._xmlHttp();
this._AddEventToXHP(_xhp, fun || function(){} ,isxml);
_xhp.open("GET",url,bool);
_xhp.send(null);
}
ajax请求的时候,IE出现拒绝访问的错误,同域名无跨域,调试了半天还是调试不出问题?
FF调试看到错误信息:
Error loading content (NS_ERROR_DOCUMENT_NOT_CACHED)
text/html (NS_ERROR_DOM_BAD_URI)
如果也遇到这种情况,实在想不出啥原因了的话,看看是不是http://和https://的互访。