Jump to content

Run js_function() if ajax response = "1" ( please read, you may be able to help )


lynxus

Recommended Posts

Hi Guys,

 

I have a question..

I have the below html5 code that will show a html5 notification:

    <script>
    
    function RequestPermission (callback) {
        window.webkitNotifications.requestPermission(callback);
    }
    
    function showNotification(){
        if (window.webkitNotifications.checkPermission() > 0) {
            RequestPermission(showNotification);
        }
        else {
          window.webkitNotifications.createNotification("http://a1.twimg.com/profile_images/710503034/lillypad_rss_normal.png", "TITLE",
              "Hello, Im a message.").show();
        }
    }
    
    </script> 

How can I use ajax to call notify.php and if notify.php returns the value of "1" the page / ajax will then call the showNotification() function?

 

Please anyone?

This is killing me and I suck @ JS / Ajax / Jquery..

 

An example code would be ace.

 

 

Essentially im looking for something like.

 

ajaxrequest="notify.php"

if ajaxrequest.answer = "1" {

showNotification();

}

 

Any thoughts?

This has been resolved from some fellows over at webmaster-talk.com

 

    $(document).ready(function() {
        $.ajax({
            url: 'notify.php',
            success: function(data) {
                if (data == "1") {
                    showNotification();
                }
            }
        });
    });

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.