2016-08-12 6 views
-1

私が従業員のフォロー/アンフォロー時にユーザーが通知を見ることができるソーシャルサイトを構築しています。 購入したプラグインには、通知件数を通知/通知する機能があります。htmlでこの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; 
    } 

通知のために作成したメニュー項目でこれを呼び出すにはどうすればよいですか?

多くのご協力をいただきありがとうございます。私はjqueryのAJAXを使用していたようにページがないよう

+0

javascriptを使用してajaxを使用する – Sumit

答えて

0

あなただけ

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

使用AJAXメソッドはPHP関数からデータを取得するために... ..次のようにAJAXを使用してHTMLに を関数を呼び出すことができますそれらのデータを取得するためにリロードします。

AJAX呼び出し例(jQueryの)

$.ajax({ 
    type: 'POST', 
    url: 'test.php', 
    data: { postVar1: exp1, postVar2: exp2 }, 
    beforeSend:function(){ 
    // this is where we append a loading image 
    // $('#ajax-panel').html('<div class="loading"><img src="/images/loading.gif" alt="Loading..." /></div>'); 
    alert('...requesting'); 
    }, 
    success:function(data){ 
    alert(data); 
    }, 
    error:function(){ 
    // failed request; give feedback to user 
    alert('ERROR'); 
    } 
}); 
0
<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); 
     }); 
} 

注:ファイルの実際の/フルパスで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; 
    } 

あなたのコードを入れて、これはあなたを助けることを願っています!

関連する問題