再谈jQuery跨任何域 09 April 2012 11:25 Monday by 小屋 浏览(265)

跨域相关的文章老早写过几篇:

jquery url检测遇到的jquery跨域问题及JSONP的使用

PHP - 利用P3P实现跨域

HTTP和HTTPS跨域共享session解决办法

本文是对第一篇的实例补充。

js脚本

$.getJSON ('http://sjolzy.cn/?callback=? &a=1&b=2', function(data) {
    if (typeof(data) == 'object') {
        $.each(data,function(i,j){
            // ...
        });
    }
});

服务端代码

阅读全文>>

jquery ajax的async参数导致火狐浏览器闪屏 06 April 2012 11:15 Friday by小屋 浏览(368)

先提下关于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的Ajax代码 23 January 2012 17:33 Monday by小屋 浏览(428)

[代码] [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);    
}

阅读全文>>

prototype 的dom:loaded在ie下不兼容问题 02 November 2011 12:06 Wednesday by小屋 浏览(488)

Magento默认采用的prototype库,遇到关于prototype的document.observe('dom:loaded', function() {}); 的用法在IE不起作用的问题(在火狐下工作OK)。

document.observe('dom:loaded', function() {
    alert('dom:loaded');
});

最后暂时解决这个兼容问题的处理是:

添加浏览器判断,在IE浏览器下改用Event.observe(window, 'load', function() {});

js判断浏览器

var Browser = {
    'isIE' : (navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0),

阅读全文>>

JQuery和Prototype区别小结 22 July 2011 16:35 Friday by小屋 浏览(1615)

jQuery使用得比较顺手也比较喜欢,不得已也要用Prototype,小小整理下区别。。

页面载入

  1. // JQuery
    
    
    
  2. $ ( document ). ready ( function () {
  3.         // Code
  4. });

 

  1. // JQuery Shorthand
    
    
    
  2. $ ( function () {
  3.         // Code
  4. });

 

  1. // Prototype
    
    
    
    

阅读全文>>