AJAX jquery调用页面加载和js插件初始化后如何在页面加载成功后修改或设置选项? [英] AJAX jquery call after page loaded and js plugins initialized how can I modify or set option after page loaded successfuly?

查看:207
本文介绍了AJAX jquery调用页面加载和js插件初始化后如何在页面加载成功后修改或设置选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我正在使用summernote.js,而且我对Jquery和Ajax并不熟悉。我想知道如何在页面加载异步ajax调用之后设置提及选项(我不想等待)?其实我的问题是我应该在哪里设置提及选项,应该怎么做?我可以从控制器检索提及选项但是在初始化中设置它会导致问题如果我使异步调用页面元素没有正确显示(不初始化)如果我使同步调用页面等待1秒然后显示(我不想要)。



我尝试过:



 jQuery.extend({
getMentions: function (){
$ .ajax({
类型: get
dataType: json
async: true
url : getMentions // < span class =code-comment>/ CreateTicket / getCustomerProjects
成功: fun ction (数据){
console .log(data);
result = data;

}
});
// alert(result);
返回结果;
}
});





已准备好文件

  var  valset = $。getMentions(); 
$( 。hint2mention)。summernote({
height:< span class =code-digit> 100 ,
toolbar: false
提示:{
提及: valset,
匹配:/ \B @(\ w *)$ /,
搜索: function (关键字,回调){
回调($。grep( this .mentions, function (item){
return item.indexOf(keyword)== 0 ;
}));
},
内容: function (item){
return ' @' + item;
}
}
});

解决方案

.ajax({
type: get
dataType: json
async: true
url: < span class =code-string> getMentions, // / CreateTicket / getCustomerProjects
成功: function (data){
console .log(data );
result = data;

}
});
// alert(result);
返回结果;
}
});





已准备好文件

  var  valset = 


.getMentions();


。hint2mention)。summernote({
height: 100
工具栏: false
提示:{
提及:valset,
匹配:/ \B @(\\ \\w *)

Hi people I am using summernote.js and I am not familliar to Jquery and Ajax so much. I am wondering that How can I set mentions option after page loaded with asychronous ajax call(I dont want to wait)? Actually my question is where should I set mentions option and how should ? I am able to retrieve mentions options from controller but setting it in initialization cause problem if I make async call page element doesnt display properly(doesnt initialize) if I make synch call page waits like 1 second and displays then(which I dont want).

What I have tried:

jQuery.extend({
    getMentions: function () {
        $.ajax({
            type: "get",
            dataType: "json",
            async: true,
            url: "getMentions", // "/CreateTicket/getCustomerProjects"
            success: function (data) {
                console.log(data);
                result = data;
                
            }
        });
        //alert(result);
        return result;
    }
});



in document ready

var valset =$.getMentions();
$(".hint2mention").summernote({
  height: 100,
  toolbar: false,
  hint: {
    mentions: valset,
    match: /\B@(\w*)$/,
    search: function (keyword, callback) {
      callback($.grep(this.mentions, function (item) {
        return item.indexOf(keyword) == 0;
      }));
    },
    content: function (item) {
      return '@' + item;
    }    
  }
});

解决方案

.ajax({ type: "get", dataType: "json", async: true, url: "getMentions", // "/CreateTicket/getCustomerProjects" success: function (data) { console.log(data); result = data; } }); //alert(result); return result; } });



in document ready

var valset =


.getMentions();


(".hint2mention").summernote({ height: 100, toolbar: false, hint: { mentions: valset, match: /\B@(\w*)


这篇关于AJAX jquery调用页面加载和js插件初始化后如何在页面加载成功后修改或设置选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆