0

为什么这不起作用?只有success呼吁第一反应是有效的。

for(i = 1; i <= 6; i++) {

    $.ajax({
        url : 'runTest.php',
        type : 'post',
        data : "testNumber="+i+"&url=" + testUrl,
        dataType : 'json',
        success : function(data) {

        var row = $('<tr />');
            $('<td />').text(data.testName).appendTo(row);
            $('<td />').text(data.testSeverity).appendTo(row);
            $('<td />').text(data.testResult).appendTo(row);
            $('<td />').text(data.testResultDetail).appendTo(row);
            $('<td />').text(data.testDescription).appendTo(row);

            $('table#results tbody').append(row);

        }
    });

}

在此处输入图像描述

4

1 回答 1

1

服务器端可能有问题。您一次触发了六次相同的 PHP 脚本;也许数据库(或其他)锁定了第一个请求,而其他五个返回错误您没有检查。在这种情况下,您需要在 PHP 中包含某种while...sleep循环,等待数据库可用。

当我使用 PHP 脚本从谷歌地图检索数据并遇到请求限制时,这是我为类似问题所做的。但是这个想法很简单,你应该可以根据自己的需要修改它:

$params = http_build_query($_GET);
$url = "http://maps.googleapis.com/maps/api/directions/json?sensor=false&" . $params;

$json = file_get_contents($url);
$status = json_decode($json)->status;

// check for over_query_limit status
while ($status=="OVER_QUERY_LIMIT") {
    sleep(0.2); // seconds
    $json = file_get_contents($url);
    $status = json_decode($json)->status;
}
于 2013-04-22T18:09:38.530 回答