在 wordpress 中,我创建了一个插件,其中包含以下文件
统计访客
<?php
/*
Plugin Name: Wp Visitor Statistics
Plugin URI:
Description: Statistics about Visitors
Author:
Version: 1.0.1
Author URI:
*/
ob_start();
define('STATISTICS_FOLDER', dirname(plugin_basename(__FILE__)));
//CREATING MENU PAGES IN SIDEBAR
add_action('admin_menu','statistics_admin_menu');
function statistics_admin_menu() {
$icon_url=get_option('siteurl').'/wp-content/plugins/'.STATISTICS_FOLDER."/lea.png";
add_menu_page("Statistics","Statistics",10,__FILE__,"Settings",$icon_url);
add_submenu_page(__FILE__,"Stat Report","Statistics Report",10,"visitor_stat/statreport.php");
}
function Settings()
{
$plugindir = get_option('siteurl').'/wp-content/plugins/'.STATISTICS_FOLDER.'/';
echo "<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'/></script>\n";
echo "<br/>";
echo "<script type='text/javascript' src='$plugindir/calendar/myfuncvisit.js'/></script>\n";
echo "<br/>";
echo "<script type='text/javascript' src='$plugindir/calendar/jquery.datepick.js'/></script>\n";
echo "<br/>";
echo "<link rel='stylesheet' href='$plugindir/calendar/jquery.datepick.css' type='text/css' />\n";
echo "<br/>";
echo "<script type='text/javascript'>
$(function() {
$('#popupDatepicker').datepick({dateFormat: 'yyyy-mm-dd'});
});
</script>";
echo "<br/>";
echo "<div class='wrap'>
<form action='' name='frm1'>
<strong>Todays Visit : <span id='todays_visit'> </span> | Overall Visit :<span id='overall_visit'></span> ( Original Data )<br /></strong><br />
Todays Visit plus : <input type='text' name='todays_visit_plus' id='todays_visit_plus' value=''/><br /><br />
Overall Visit plus : <input type='text' name='overall_visit_plus' id='overall_visit_plus' value=''/><br /><br />
Overall Visit Start Date : <input type='text' class='overall_visit_startdate' id='popupDatepicker'><br /><br />
<div id='msg_save'></div>
<input type='button' name='save' id='save' value='save'/>
</form>
</div>";
}
?>
然后它调用另一个文件 js
myfuncvisit.js
// JavaScript Document
$(document).ready(function(){
// loading image displaying function
function loading_show(divid){
$('#'+divid).html("<div class='item' style='padding:45% 0;text-align:center;font-size:11px;color:#666666;'><center><img width='16' height='16' src='loading.gif'><br>Loading</center></div>").fadeIn('swing');
}
// function to show the feed list
function loadData(){
$.ajax
({
type: "POST",
//url: "blog/wp-content/plugins/visitor_stat/stats-operations.php",
url: "/blog/wp-admin/admin.php?page=visitor_stat/stats-operations.php",
data: "type=all",
success: function(msg)
{
alert(msg);
part = msg.split('#');
$("#todays_visit").ajaxComplete(function(event, request, settings)
{
$("#todays_visit").html(part[0]);
});
$("#overall_visit").ajaxComplete(function(event, request, settings)
{
$("#overall_visit").html(part[1]);
});
$("#todays_visit_plus").ajaxComplete(function(event, request, settings)
{
$("#todays_visit_plus").val(part[2]);
});
$("#overall_visit_plus").ajaxComplete(function(event, request, settings)
{
$("#overall_visit_plus").val(part[3]);
});
$("#popupDatepicker").ajaxComplete(function(event, request, settings)
{
$("#popupDatepicker").val(part[4]);
});
}
});
}
function saveData(){
$.ajax
({
type: "POST",
url: "/blog/wp-admin/admin.php?page=visitor_stat/stats-operations.php",
//url: "blog/wp-content/plugins/visitor_stat/stats-operations.php",
data: "type=save&d1="+d1+"&d2="+d2+"&d3="+d3,
success: function(msg)
{
alert(msg);
loadData();
$("#msg_save").ajaxComplete(function(event, request, settings)
{
$("#msg_save").html(msg);
setTimeout('',10000);
$("#msg_save").html(' ').fadeIn('swing');
});
}
});
}
loadData(); // For first time page load default results
$('#save').live('click',function(){
d1=$('#todays_visit_plus').val();
d2=$('#overall_visit_plus').val();
d3=$('#popupDatepicker').val();
saveData(d1,d2,d3);
});
});
但是当我在 wordpress admin 中运行文件时,它显示 admin.php?page=visitor_stat/stats-operations.php /blog/wp-admin 的内部服务器错误并且它不加载 ajax 页面
我尝试了几次,我找不到解决方案。我认为这个问题可能有正确的解决方案。任何人都可以帮助我解决这个问题。
显然,ajax 函数 URL : POST 不起作用。提前感谢解决这个问题