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.
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.
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 :)
精彩评论