这段带有Javascript / jQ的PHP代码.如何


This piece of PHP code with Javascript / jQ... How?

<?php
            if(strstr(file_get_contents('http://api.alphenweer.nl/api.php?apikey=Hier uw api sleutel&server=servercheck'), '1')){
                echo 'AlphenWeer.nl Api server is online en werkend.';
            }
            else
            {
                echo 'AlphenWeer.nl Api server if offline of niet werkend, of uw API code klopt niet.';
            }
    ?>

如何使用javascript和/或jQuery执行此操作?我只知道 AJAX 部分,但随后检查数据中是否有 1。如何?

您可以使用 Mozilla 文章中描述的indexOf方法。

if (str.indexOf('1')>-1) {
    // found
}
else 
{
    // not found
}

其中str包含 AJAX 部件返回的字符串。