ie6下jsonp返回失效问题

问题描述:

在ie6下用jsop,用fillder查看的确是已经发送成功并且已经有返回了,状态是成功的。但是成功函数就是不执行。

(function($){
$.fn.plugin_name = function(){
    var methods = {
        getSomeThing: function(callback){
            $.ajax({
                type: 'GET',
                dataType: 'jsonp',
                url: 'http://thirdparty.com/get',       
                success: function(response){
                    callback(response);
                }
            });
        },
        getDetail: function(callback){
            $.ajax({
                type: 'GET',
                dataType: 'jsonp',
                url: 'http://thirdparty.com/getdetail',
                data:{id:1},
                success: function(response){
                    //this code block has never executed in IE6
                },
                error: function(request, status, error){
                    alert(request.statusText); // i get "success" in IE6
                    alert(status); // i get "parseerror" in IE6
                    alert(error.error); // i get [object Error] in IE6
                }
            });
        }
    };

    return this.each(function(){
        var self = $(this);
        methods.getSomeThing(function(response){ // work OK
            //process response
            self.html(response.html); // work OK

            self.append('<a href="javascript:;" id="linkDetail">View Detail</a>');

            self.on('click','#linkDetail',function(){
                //i make an ajax request here
                methods.getDetail(function(response){
                    //failed!!
                });
            });

        });
    });
}

解决方法:

在元素click的时候写下event.preventDefault();
例如:

self.on('click','#linkDetail',function(event){
        event.preventDefault();
            //i make an ajax request here
            methods.getDetail(function(response){
                //failed!!
            });
        });

ps:ie6下会因为event.preventDefault();报错,只要写成event.returnValue = false;就好。
更多内容请访问:http://www.78oa.com/news/news_2_16_1.html

无标签
分享到: