Reputation: 39
I make a jquery plugin look like:
(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!!
});
});
});
});
}
})(jQuery);
I used jsonp to making requests across domains.
It works fine on Firefox, Chrome, IE7,8 but no luck on IE6.
There is something wrong at method getDetail, when i click View Detail link, i got errors.
I try to debug it with Fiddler, then i don't see any request when i click View Detail, but i still got the errors ?!
I can not figure this problem, someone help me, please! Thank you so much!
Upvotes: 0
Views: 1054
Reputation: 39
I solved the problem! I just want to share with you this tip.
Seem there is something wrong when event click was fired on an anchor like this:
<a href="javascript:;" id="linkDetail">View Detail</a>
I use event.preventDefault() in this case, so the default action of the event will not be triggered.
self.on('click','#linkDetail',function(event){
event.preventDefault();
//i make an ajax request here
methods.getDetail(function(response){
//failed!!
});
});
Then everything work fine in IE6!
Upvotes: 1