我有一个getJSON请求,该请求会转到wordpress站点根目录(htdocs)上的PHP页面。它应该发出JSON请求并返回值以在Wordpress页面上追加div。我正在使用脚本和样式插件将javascript添加到单个页面的主体中。
当我在本地主机上测试脚本(没有Wordpress)时,它工作得很好。但是,当我将其添加到Wordpress页面并尝试运行脚本时,出现以下错误:
“未捕获的TypeError:无法读取null的属性‘events’”
这是我的剧本。我把eventbrite\\u放在api2上。服务器根目录(htdocs)中的php。不确定这是否只是路径问题或其他问题,请提供帮助。
jQuery.getJSON(\'eventbrite_api2.php\', {eventid: \'14900532895\', function:\'next\'},
function (response) {
var upcoming = response; //we\'re naming the response \'upcoming\' for easier reading
console.log(upcoming.events[0]); // this is for testing, comment this out when not needed
var date = new Date(upcoming.events[0].start.utc);//this formats the date to local time zone
console.log(date); //this prints the next date, for testing..
event_start = date.toLocaleString(\'en-US\', { weekday: \'long\', day: \'numeric\', month: \'long\', year: \'numeric\', hour: \'numeric\', minute: \'numeric\', hour12: true, timeZone: "America/New_York" });//this formats the date to eastern time zone, and makes some other formatting of the date
var content = "<h4>" + upcoming.events[0].name.text + "</h4><p>Next Tour: " + event_start + "</p>" ;
$("#eventbrite").append(content);
});