admin管理员组文章数量:1305141
I am using jQuery's $.ajax() to get some data. I'd like to include that data in a popover dialog. I'm using the Twitter Bootstrap popovers.
It's not working; I believe the problem is that the JS for the popovers gets loaded before the data arrives.
How do I do something like:
<script src="{{ STATIC_URL }}js/bootstrap-popover.js"></script>
inside of my $.ajax() success function?
var request = $.ajax({
url: requestUrl,
dataType: "jsonp",
success: function(data) {
...
}
I am using jQuery's $.ajax() to get some data. I'd like to include that data in a popover dialog. I'm using the Twitter Bootstrap popovers.
It's not working; I believe the problem is that the JS for the popovers gets loaded before the data arrives.
How do I do something like:
<script src="{{ STATIC_URL }}js/bootstrap-popover.js"></script>
inside of my $.ajax() success function?
var request = $.ajax({
url: requestUrl,
dataType: "jsonp",
success: function(data) {
...
}
Share
Improve this question
asked Jan 10, 2012 at 21:42
coffee-grindercoffee-grinder
27.6k19 gold badges59 silver badges82 bronze badges
2 Answers
Reset to default 8you can use jQuery's $.getScript
method:
success: function(data) {
$.getScript("myurl/js/bootstrap-popover.js");
}
In trying to offer you a better solution, your tentative conclusion doesn't make sense to me. You should be able to include the popover javascript long before your ajax call and then use code to actually invoke the popover or configure it on any newly added content in your success handler.
There is no reason I'm aware of to load the popover js inside the success handler. Load it beforehand (in the normal way you load your other scripts) and then use it in the success handler for your ajax call. To help with how you'd use the popover script, we'd need to know more about what you're trying to do with it.
本文标签: How do you load a Javascript file inside of the success function for ajax()Stack Overflow
版权声明:本文标题:How do you load a Javascript file inside of the success function for $.ajax()? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741798115a2398058.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论