murat
murat

Reputation: 3

Getting the value of a link by Javascript

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.

Upvotes: 0

Views: 978

Answers (2)

Paul D. Waite
Paul D. Waite

Reputation: 98796

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 :)

Upvotes: 2

Gausie
Gausie

Reputation: 4359

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.

Upvotes: 6

Related Questions