Home Automatically OneSignal subscribe after AJAX response
Reply: 0

Automatically OneSignal subscribe after AJAX response

user934
1#
user934 Published in April 22, 2018, 4:54 am

I would like a user be subscribed for web push notifications after create an account via AJAX, so looking the example of Custom Link Permission my code is like this:

$.ajax({

  type: "POST",
  url: "mypage.php",
  data:{ //data user and pass
  },
  dataType: 'json',
  cache: false,
  success: function(data)
  {

  function subscribe() {
    OneSignal.push(["registerForPushNotifications"]);
    event.preventDefault();
  }

  var OneSignal = OneSignal || [];

  OneSignal.push(function() {
    if (!OneSignal.isPushNotificationsSupported()) {
        return;
    }
    OneSignal.isPushNotificationsEnabled(function(isEnabled) {
        if (isEnabled) {
            // The user is subscribed to notifications
            // Don't show anything
        } else {
            subscribe();
        }
    });
  });
 }
});

But it doesn't work, how can I get it? I would like some help.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.304015 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO