我在 WordPress 中有一个 AJAX 函数,它调用一个 PHP 函数来返回数据库中临时记录的值。
当我使用 jQuery 调用该函数时,我收到了结果,但是它总是在值后面附加了一个额外的 0(零)。
这是我的 jQuery 函数:
(function($) {
$(document).ready( function() {
var AdvancedDashboardWidget = function(element, options)
{
var ele = $(element);
var settings = $.extend({
action: '',
service: '',
countof: '',
query: '',
callback:''
}, options || {});
this.count=0;
var url='';
switch(settings.service)
{
case 'facebook':
if(settings.countof=='likes' || settings.countof=='talks')
{
ajaxCall(action,ele,settings);
}
}
};
var ajaxCall = function(action,ele,settings){
opts = {
url: ajaxurl, // ajaxurl is defined by WordPress and points to /wp-admin/admin-ajax.php
type: 'POST',
async: true,
cache: false,
dataType: 'json',
data:{
action: settings.action // Tell WordPress how to handle this ajax request
},
success:function(response) {
//alert(response);
ele.html(response);
return;
},
error: function(xhr,textStatus,e) { // This can be expanded to provide more information
alert(e);
//alert('There was an error');
return;
}
};
$.ajax(opts);
};
$.fn.advanceddashboardwidget = function(options)
{
return this.each(function()
{
var element = $(this);
// Return early if this element already has a plugin instance
if (element.data('advanceddashboardwidget')) return;
// pass options to plugin constructor
var advanceddashboardwidget = new AdvancedDashboardWidget(this, options);
// Store plugin object in this element's data
element.data('advanceddashboardwidget', advanceddashboardwidget);
});
};
});
})(jQuery);
还有更多的辅助函数,但是这是与 WordPress 通信并返回 PHP 函数值的主要 jQuery 函数。
问题是,如果该值返回为“ 99
”,例如,它将返回为“ 990
”
这是 jQuery 调用的 PHP 函数:
/**
* Get Facebook Likes
*/
public function get_facebook_likes(){
echo 99;
}
如果我将以上内容更改为return 99;
我收到纯 0