0

I want to send the notification to the website.

I don't have any user information. Our website is not having login and signup option. So that we don't have user data.

but I want to send the notification to the website. how can I implement this type of architecture?

Please explain.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Mahesh
  • 93
  • 1
  • 8
  • In our website we are publishing articles. if any new article published then I want to send notification to the user if they allows notifications on my website.please help me for this also. – Mahesh Sep 26 '17 at 09:37
  • You can use Pushpad: it has a plugin for Wordpress that allows you to do exactly that. If you don't use Wordpress you can trigger notifications from the dashboard or using the libraries. See https://pushpad.xyz/docs/sending_push_notifications – collimarco Sep 26 '17 at 12:50

1 Answers1

1

One possible option is to have your site perform simple interval function, that triggers every x-seconds and requests data (with ajax) from the server.

Then you handle it on client side, whether there is new data or not.

setInterval(function(){ 
    $.ajax(...
         , success : function (res) {
             if(res.data.newData){
                  //push new data to the site
             }
         }
    );
}, 3000);

This is just an example of a function that requests data from server every 3 seconds.

Miha Jamsek
  • 1,193
  • 2
  • 17
  • 33
  • If the website is not open in the browser then also notification will send by this logic or not? – Mahesh Sep 28 '17 at 09:25
  • no, if page is not loaded, the request won't be made and therefore server will not respond to client. – Miha Jamsek Sep 28 '17 at 10:03
  • we can do this by using service worker java script file.but I don't know how to do that?if you know please tell me – Mahesh Sep 28 '17 at 10:12
  • I am not sure i follow the question. On the client side you do as I wrote and set ajax to request /get-notification. Then on server you map request to /get-notification and there you respond with data you want to push. What are you using as server side? – Miha Jamsek Sep 28 '17 at 10:17
  • php,java script – Mahesh Sep 28 '17 at 11:39
  • well, then in your html file (or javascript if its external) you make interval function that performs ajax call, while in your php file you handle that request, get your data and send it back to yoru client (your javascript code) take a look at this: https://stackoverflow.com/questions/2269307/using-jquery-ajax-to-call-a-php-function – Miha Jamsek Sep 28 '17 at 13:24