创建要在getJSON回调中使用的函数

问题描述 投票:-1回答:1

我想要一个可以在不同的getJSON调用中使用的函数,但是出现未定义的数据错误

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))

});

不起作用,但是

$.getJSON(ajaxurl,args,function(data){console.log(data)});

在控制台中很好地显示我的JSON数据。

如何创建可以再次使用的功能? (最终,该日历将在页面加载时填充本月,其他月份则单击下一个和上一个!)

jquery function getjson
1个回答
0
投票

您不需要在调用中添加参数,因为参数是由回调本身传递的。

$.getJSON(ajaxurl, args, populateCalendarMonth)
© www.soinside.com 2019 - 2024. All rights reserved.