Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Run js_function() if ajax response = "1"
Old 09-28-2010, 01:37 PM Run js_function() if ajax response = "1"
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Hi Guys,

I have a question..
I have the below html5 code that will show a html5 notification:
Code:
    <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", "NEW chat request!", 
              "Someone would like to talk to you.").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?

notify.php will contain only a 0 or 1. The above script is already in the head of the document thats calling the notify.php, So theres no need for the evaljs

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?
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE



Last edited by lynxus; 09-28-2010 at 02:00 PM..
lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
 
Register now for full access!
Old 09-28-2010, 02:21 PM Re: Run js_function() if ajax response = "1"
Ultra Talker

Posts: 366
Name: Steve
Location: Miami, FL, Earth
Trades: 0
Code:
    <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", "NEW chat request!", 
              "Someone would like to talk to you.").show(); 
        }
    }
    
    $(document).ready(function() {
        $.ajax({
            url: 'notify.php',
            success: function(data) {
                if (data == "1") {
                    showNotification();
                }
            }
        });
    });
    </script>
__________________
- Steve

President,
Please login or register to view this content. Registration is FREE
smoseley is offline
Reply With Quote
View Public Profile Visit smoseley's homepage!
 
Old 09-28-2010, 02:40 PM Re: Run js_function() if ajax response = "1"
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Thanks man.
My brain has been bleeding over this.

One way i did also manage it ( in a very round about way lol )

Is like so:
Code:
<textarea id="notifydata"></textarea>

 $('#notifydata').load('notify.php?_='+Math.random());
  
  var neednotify = document.getElementById('notifydata');
    if(neednotify.value == 1) {
             showNotification();
             
}
But your way is SOOOO much cleaner lol.
Thanks man.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Reply     « Reply to Run js_function() if ajax response = "1"
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.50044 seconds with 12 queries