Jump to content

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


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();
                }
            }
        });
    });

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.