Javascript 无法从AJAX调用中获取(可移动)函数,但它可以在其他地方工作
编辑:这个问题似乎只发生在Chrome上。Firefox很好。 Footable是一个JQuery插件 “Footable”插件使用以下函数使.table类具有良好的布局:Javascript 无法从AJAX调用中获取(可移动)函数,但它可以在其他地方工作,javascript,jquery,ajax,footable,Javascript,Jquery,Ajax,Footable,编辑:这个问题似乎只发生在Chrome上。Firefox很好。 Footable是一个JQuery插件 “Footable”插件使用以下函数使.table类具有良好的布局: jQuery('.table').footable({ "columns": result, "rows": response }); 我想在AJAX调用中运行函数: $.get('../php/campaignmanagement.php', function(response){ re
jQuery('.table').footable({
"columns": result,
"rows": response
});
我想在AJAX调用中运行函数:
$.get('../php/campaignmanagement.php', function(response){
response = JSON.parse(response);
var columns = Object.keys(response[0]);
var result = columns.map(x => {
return {
title: x,
name: x
}//end return
});
//FUNCTION HERE
jQuery('.table').footable({
"columns": result,
"rows": response
});
//FUNCTION ABOVE
......... Other irrelevant code...
});
这给了我以下错误:
jQuery(...).footable is not a function
但是,如果我将函数移到AJAX函数之外,它就会工作
e、 g
我需要能够在AJAX中运行该函数。
为什么AJAX会导致一切崩溃
仅供参考:HTML文档调用如下脚本:(activitymanagement.js是运行上述功能的文件)
您在这里使用的是两个不同的jQuery对象,第一个是
$
(除非您将其分配给了我们看不到的其他对象)和jQuery
。您可以在对象本身中使用$
对象,或者获取AJAX请求闭包中可用的元素的引用
// grab a reference to the table using jquery
var table = $('.table')
$.get('../php/campaignmanagement.php', function(response){
response = JSON.parse(response);
var columns = Object.keys(response[0]);
var result = columns.map(x => {
return {
title: x,
name: x
}//end return
});
table.footable({
"columns": result,
"rows": response
});
});
有趣的是,这似乎允许足部负重,但是,它没有显示任何结果。另外,我发现这个问题只发生在Chrome中。首先尝试使用静态虚拟数据,看看footable本身是否正常工作,如果可以使用AJAX调用中的静态数据,那么很可能是映射数据的问题。
<script src="../vendors/jquery/jquery.js"></script>
<script src="../vendors/footable/js/footable.js"></script>
<script src="../vendors/foundation 6/foundation.js" type="text/javascript"></script>
<script src="../js/campaignmanagement.js"></script>
// grab a reference to the table using jquery
var table = $('.table')
$.get('../php/campaignmanagement.php', function(response){
response = JSON.parse(response);
var columns = Object.keys(response[0]);
var result = columns.map(x => {
return {
title: x,
name: x
}//end return
});
table.footable({
"columns": result,
"rows": response
});
});