ajax 使用问题

前端之家收集整理的这篇文章主要介绍了ajax 使用问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

addTestimonialsElement: function(){

/*不能在ajax 中直接用this 因为这样this 指向的就是ajax本身对象*/

var my_this = this;
//var content = document.getElementsByTagName("body")[0].innerHTML;
var contents = document.getElementsByTagName("iframe");
//var content = $(contents[0]).contents().find("body").html();

var size = contents.length;
var i = 0;
var value = 0;
var temp = "";
for(i;i<size;i++){
temp = $(contents[i]).contents().find("body").html();
value += temp.indexOf('widget-name="rating"',0);
}


if(value > -1){
var em = $("<div widget-name='testimonials' data-type='seDynamicWidget'><div class='widgetBox' widget-name='testimonials'></div></div>").appendTo(my_this.options.widgetParent);
em.seDynamicWidget();
my_this._scrollToNewWidget($(em).offset().top);
}else{
var http = location.protocol;
var slashes = http.concat("//");
var url = slashes.concat(window.location.host);

$.ajax({
url: url+"/widget/widget-ratings",
dataType : "jsonp",
jsonp: "callbackparam",
async:false,
success: function(msg){
if(msg.ratings == 0){

$('#confirm-testimonials-modal').modal({show:true});

//要先off不然会出现倍数调用问题

$('#confirm-testimonials-modal a#add-testimonials-widget-now').off('click');

//绑定on

$('#confirm-testimonials-modal a#add-testimonials-widget-now').on('click',function(e){ var em = $("<div widget-name='testimonials' data-type='seDynamicWidget'><div class='widgetBox' widget-name='testimonials'></div></div>").appendTo(my_this.options.widgetParent); em.seDynamicWidget(); my_this._scrollToNewWidget($(em).offset().top); $('#confirm-testimonials-modal').modal('hide'); }); $('#discard-and-cancel').off('click'); $('#discard-and-cancel').on('click',function(e){ $('#confirm-testimonials-modal').modal('hide'); return false; }) }else{ var em = $("<div widget-name='testimonials' data-type='seDynamicWidget'><div class='widgetBox' widget-name='testimonials'></div></div>").appendTo(my_this.options.widgetParent); em.seDynamicWidget(); my_this._scrollToNewWidget($(em).offset().top); } } }); } } 原文链接:https://www.f2er.com/ajax/164282.html

猜你在找的Ajax相关文章