Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在html中调用此php函数_Php_Html - Fatal编程技术网

如何在html中调用此php函数

如何在html中调用此php函数,php,html,Php,Html,我正在建立一个社交网站,用户可以在有人跟踪/取消跟踪时看到通知。 购买的插件中提供了一个功能,用于通知/提醒用户通知的数量 /* * Helper functions * * Use these functions inside themes to display various notification-related information */ function ip_notifications_menu_item() { if(notification_co

我正在建立一个社交网站,用户可以在有人跟踪/取消跟踪时看到通知。 购买的插件中提供了一个功能,用于通知/提醒用户通知的数量

/*
 * Helper functions
 *
 * Use these functions inside themes to display various notification-related information
 */


 function ip_notifications_menu_item() {
        if(notification_count() > 0)
            $item = '<a href="#" class="notifications-bell">
<i class="fa fa-bell"></i><sup>' . notification_count() . '</sup></a>
<div class="notifications-container">' . do_shortcode('[notifications]') . '</div>';
        else
            $item = '<a href="#" class="notifications-bell">
<i class="fa fa-bell-o"></i></a><div class="notifications-container">' . do_shortcode('[notifications]') . '</div>';

        return $item;
    }
/*
*辅助函数
*
*在主题中使用这些函数可以显示各种通知相关信息
*/
功能ip_通知_菜单_项(){
如果(通知计数()>0)
$item='1
“.do_短代码(“[通知])”)”;
其他的
$item=''.do_短代码('[notifications]');
返回$item;
}
如何在我为通知创建的菜单项上调用此选项


非常感谢你的帮助

您可以使用AJAX在html中调用函数,如下所示。。 当我使用jQueryAjax时

$.get('yourpage.php',function(data){
 alert(data);
});

使用AJAX方法从php函数获取数据,因为您的页面不希望重新加载以获取这些数据

ajax调用示例(jQuery)

$.ajax({
键入:“POST”,
url:'test.php',
数据:{postVar1:exp1,postVar2:exp2},
beforeSend:function(){
//这是我们附加加载图像的地方
//$('#ajax面板').html('');
警报(“…请求”);
},
成功:功能(数据){
警报(数据);
},
错误:函数(){
//请求失败;向用户提供反馈
警报(“错误”);
}
});
显示通知
函数onrequest(){
$.post('notificationfile.php').success(函数(响应){
//您可以根据需要使用此响应
警报(响应);
});
}
注意:将notificationfile.php替换为文件的实际/完整路径

并在notificationfile.php中放入您的代码

/*
 * Helper functions
 *
 * Use these functions inside themes to display various notification-related information
 */


 function ip_notifications_menu_item() {
     if(notification_count() > 0)
        $item = '<a href="#" class="notifications-bell">
<i class="fa fa-bell"></i><sup>' . notification_count() . '</sup></a>
<div class="notifications-container">' . do_shortcode('[notifications]') . '</div>';
        else
            $item = '<a href="#" class="notifications-bell">
<i class="fa fa-bell-o"></i></a><div class="notifications-container">' . do_shortcode('[notifications]') . '</div>';

        return $item;
    }
/*
*辅助函数
*
*在主题中使用这些函数可以显示各种通知相关信息
*/
功能ip_通知_菜单_项(){
如果(通知计数()>0)
$item='1
“.do_短代码(“[通知])”)”;
其他的
$item=''.do_短代码('[notifications]');
返回$item;
}

希望这对你有帮助

通过javascript使用ajax
<button class="btn" onclick="onrequest();">Show Notification</button>

function onrequest() {
      $.post('notificationfile.php').success(function(response){
           // you can use this response as you wish
            alert(response);
       });
}
/*
 * Helper functions
 *
 * Use these functions inside themes to display various notification-related information
 */


 function ip_notifications_menu_item() {
     if(notification_count() > 0)
        $item = '<a href="#" class="notifications-bell">
<i class="fa fa-bell"></i><sup>' . notification_count() . '</sup></a>
<div class="notifications-container">' . do_shortcode('[notifications]') . '</div>';
        else
            $item = '<a href="#" class="notifications-bell">
<i class="fa fa-bell-o"></i></a><div class="notifications-container">' . do_shortcode('[notifications]') . '</div>';

        return $item;
    }