我有一个php脚本,该脚本对mySQL数据库执行查询并返回一个数组。输出为:
[["185","177","8","10h:43m:54s","http:\/\/localhost\/toastReport\/cd7bf9ae-c21d-4746-bdd9-6934f8e5924e_ed13cfdc-403b-4a82-8f71-0da41a466e62_report\/feature-overview.html"]]
我正在使用ajax调用PHP脚本,然后尝试将数据加载到javascript数组中,然后稍后在我的HMTL页面中打印出不同的值。这是页面标题中的javascript脚本:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">
function myfunction() {
var automation = [];
jQuery.ajax({
type: "POST",
url: "http://localhost:8080/sanityTestDataCox.php",
success: function (jsonData) {
automation = jsonData;
console.log(automation);
}
});
}
</script>
我正在尝试使用页面顶部卡片中的阵列数据:
<div class="card text-white bg-primary o-hidden h-100">
<a class="card-header text-white clearfix small z-1" href="#">
<span class="float-left">COX Sanity Run </span>
</a>
<div class="card-body">
<div class="card-body-icon">
<i class="fa fa-fw fa-tasks"></i>
</div>
<div class="mr-5">Total tests: <script type="text/javascript"> myfunction(); </script></div>
<div class="mr-5">Failed tests:</div>
<div class="mr-5">Passed tests:</div>
<span class="float-right"><div class="mr-5">Run Time:</div></span>
</div>
<a class="card-footer text-white clearfix small z-1" href="http:\//localhost\/toastReport\/cd7bf9ae-c21d-4746-bdd9-6934f8e5924e_ed13cfdc-403b-4a82-8f71-0da41a466e62_report\/feature-overview.html">
<span class="float-left">View Details</span>
<span class="float-right">
<i class="fa fa-angle-right"></i>
</span>
</a>
我对如何进行这项工作感到困惑,任何信息或指向如何进行这项工作的指南的链接都将不胜感激。谢谢!
答案 0 :(得分:0)
从apache virtual hosts
返回数据时仅使用数据。
ajax()
HTML
jQuery.ajax({
type: "POST",
url: "http://localhost:8080/sanityTestDataCox.php",
success: function (data) {
console.log(data);
var total = data[0];
var failed = data[1];
var passed = data[2];
var time = data[3];
document.getElementById('total').innerHTML = "Total tests: " + total;
document.getElementById('failed').innerHTML = "Failed tests: " + failed;
document.getElementById('passed').innerHTML = "Passed tests: " + passed;
document.getElementById('runTime').innerHTML = "Run Time: " + time;
}
});
}