【发布时间】:2019-08-03 04:48:27
【问题描述】:
我想在我的页面中显示从 PHP 函数生成的装置,但只有当我按下“生成装置”按钮时。我知道应该使用 AJAX,但我无法将函数中的数据传递给 HTML 页面中的 div。
PHP 代码
$teams = array("FC FCSB", "AFC Astra Giurgiu", "FC Dinamo 1948", "FC Viitorul 2009", "CSM Politehnica Iasi", "Universitatea Craiova", "FC Botosani", "CFR 1907 Cluj");
$fixPair = new Fixture($teams);
$schedule = $fixPair->getSchedule();
$i = 1;
foreach ($schedule as $rounds) {
echo "<h5> Etapa " . $i . " </h5>";
foreach ($rounds as $game) {
echo "{$game[0]} vs {$game[1]}<br>";
}
echo "<br>";
$i++;
}
echo "<hr>";
$(document).ready(function(){
$('.button').click(function(){
var clickBtnValue = $(this).val();
var ajaxurl = 'ajax.php',
data = {'action': clickBtnValue};
$.post(ajaxurl, data, function (response) {
// Response div goes here.
document.getElementById("demo").innerHTML = "Fixtures should be displayed here";
//alert("action performed successfully");
});
});
});
<script
src="https://code.jquery.com/jquery-3.4.1.min.js">
</script>
<input type="submit" class="button" name="insert" value="GENERATE FIXTURES" />
<div id="demo"></div>
【问题讨论】:
标签: javascript php html ajax laravel