jquery - Creating a function to use in getJSON callback
问题描述
I want a function that I can use in different getJSON calls, but I get a data not defined error
jQuery(document).ready(function($) {
function populateCalendarMonth(data)
{
console.log(data);
}
var d = new Date().toJSON().slice(0, 10);
var args = {
"action": "church_admin",
"method": "calendar-render",
"date": d
};
$.getJSON(ajaxurl,args,populateCalendarMonth(data))
});
Doesn't work, but
$.getJSON(ajaxurl,args,function(data){console.log(data)});
Shows my JSON data beautifully in the console.
How do I create a function that can be used again? (eventually the calendar will be populated on page load with this month and other months on clicking next and previous!)
解决方案
You don't need to add parameter to your call, as that's passed by the callback by itself.
$.getJSON(ajaxurl, args, populateCalendarMonth)
推荐阅读
- typo3 - 按特定值对子对象进行排序
- php - 我应该如何更改 woocommerce_form_field HTML 结构?
- microsoft-graph-api - 我有任何功能可以通过这些功能将机器人添加到团队的特定频道中,而不是一般频道
- python - 关于 python argparse.add_arguments 方法的谜题
- shinydashboard - 如何使用条件面板强制进入 ShinyR tabItem 的页面顶部?
- vue.js - 从组件动态切换到标签
- r - 我的数据集在 R 中使用方差分析函数有什么问题?
- ruby-on-rails - 为什么不解析哈希的键
- python - 在执行许多队列的情况下为 Celery 指定线程
- vb.net - Word:有没有办法将光标首先定位在形状中?