tags:

views:

53

answers:

2

Here is the situation: I have a link of a page that gives only 1 or 0; http://www.mybilet.com/connectors/functionAjax.php?islem=getBosDoluKoltuk&serverId=228&showtimeId=46666

Page is not mine. So I want to build an alarm system in another page according to this value. i.e. if the value is 1, the page plays a music. How can I get this value and write the if statement in Javascript.

+6  A: 

If you're using jQuery (which I strongly suggest)

$.get("http://www.mybilet.com/connectors/functionAjax.php?islem=getBosDoluKoltuk&serverId=228&showtimeId=46666", function(number){
    if(number=="1"){
        //play music
    }
});

should to the trick.

Gausie
You should change //play music to //annoy user ;)
alex
+1  A: 

Request the page synchronously via an XMLHttpRequest, then do the if statement.

E.g., roughly:

var request = new XMLHttpRequest();
request.open("GET", "http://www.mybilet.com/connectors/functionAjax.php?islem=getBosDoluKoltuk&serverId=228&showtimeId=46666", false) // Passing false as the last argument makes the request synchronous
request.send(null);

if(request.responseText == '1') {
    // Play music
}

Ooh yes: as the other answer demonstrates, it’s a bit less fiddly if you use jQuery. But I reckon it’s good to get your hands dirty with some Real Man’s JavaScript once in a while :)

Paul D. Waite
I think that's missing an "onReadyStateChange" to make it asynchronous...
darkporter
You'll need to use the MS Active X Object in IE6 IIRC (if you plan on supporting that browser)
alex
Asynchronous, pah! That’s for trendy webdevs, with their t-shirts and their lattes and their social networking and their AJAX. In my day, we had IRC, and HTML forms. AND WE LIKED IT.
Paul D. Waite
Note that synchronous XHRs often freeze up the whole browser until they complete: http://kellegous.com/ecrits/001096
Annie