springboot怎么把数据传给前端:springboot 如何引入前端 bootstrap?
这种问题网上一搜一大堆,你可以具体找一篇文章试试,遇到问题可以针对相关问题去提问。springboot通过jar包方式引入bootstrap_个人文章 - SegmentFault 思否 这不是查查就
顺晟科技
2022-10-19 11:49:36
206
我一直试图将搜索结果导出到Excel文件(类型为.xls)中,在此之前,我一直使用纯PHP,它很有效。
但是,我的客户要求具有“实时搜索”效果,所以我不得不转向Ajax。
以下是起点:用户单击“导出”按钮,并在javascript中(在主php文件viewdata.php中):
<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js'></script>
....
$(document).ready(function () {
var guid = <?php echo $guid ?>;
var date = document.getElementById("cbXDate").value;
var key = document.getElementById("cbsearch").value;
console.log("GUID: '" + guid + "', Date: '" + date + "' Key: '" + key + "'");
$.post("export_contacts.php",
{ sGuid: guid, sDate: date, sKey: key },
function () { console.log("Complete"); } );
});
CBXDate是一个日期类型的输入字段,允许用户选择从哪里导出数据的日期,而cbsearch是一个文本输入字段,包括搜索关键字。添加控制台命令以查看代码执行的位置。
在export_contact.php中:
<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js'></script>
....
$(document).ready(function () {
var guid = <?php echo $guid ?>;
var date = document.getElementById("cbXDate").value;
var key = document.getElementById("cbsearch").value;
console.log("GUID: '" + guid + "', Date: '" + date + "' Key: '" + key + "'");
$.post("export_contacts.php",
{ sGuid: guid, sDate: date, sKey: key },
function () { console.log("Complete"); } );
});
我删除了PHP MySQL数据选择代码,只是为了调试问题(以下是完整的源代码)。
问题是:从来没有调用export_contacts.php。控制台中从未弹出“Export PHP Activated”消息。控制台只显示数据值并“完成”,即从未调用export_contacts.php。
输出:
<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js'></script>
....
$(document).ready(function () {
var guid = <?php echo $guid ?>;
var date = document.getElementById("cbXDate").value;
var key = document.getElementById("cbsearch").value;
console.log("GUID: '" + guid + "', Date: '" + date + "' Key: '" + key + "'");
$.post("export_contacts.php",
{ sGuid: guid, sDate: date, sKey: key },
function () { console.log("Complete"); } );
});
出于好奇,我替换了$.post(...)用$(“#export_div”).load(...)然后显示控制台消息:
<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js'></script>
....
$(document).ready(function () {
var guid = <?php echo $guid ?>;
var date = document.getElementById("cbXDate").value;
var key = document.getElementById("cbsearch").value;
console.log("GUID: '" + guid + "', Date: '" + date + "' Key: '" + key + "'");
$.post("export_contacts.php",
{ sGuid: guid, sDate: date, sKey: key },
function () { console.log("Complete"); } );
});
输出:
<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js'></script>
....
$(document).ready(function () {
var guid = <?php echo $guid ?>;
var date = document.getElementById("cbXDate").value;
var key = document.getElementById("cbsearch").value;
console.log("GUID: '" + guid + "', Date: '" + date + "' Key: '" + key + "'");
$.post("export_contacts.php",
{ sGuid: guid, sDate: date, sKey: key },
function () { console.log("Complete"); } );
});
但这不是我想要的,我想把输出写到一个文件中,而不是在网页中的div中显示它们。但是,“export_div”div中显示的数据是正确的,但是header部分没有运行,我知道header()调用中的奇怪之处,但是在header()调用之前我没有输出任何东西(除非来自调用viewdata.php文件的输出也计数?),下面是完整的export_contacts.php源代码:
<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js'></script>
....
$(document).ready(function () {
var guid = <?php echo $guid ?>;
var date = document.getElementById("cbXDate").value;
var key = document.getElementById("cbsearch").value;
console.log("GUID: '" + guid + "', Date: '" + date + "' Key: '" + key + "'");
$.post("export_contacts.php",
{ sGuid: guid, sDate: date, sKey: key },
function () { console.log("Complete"); } );
});
此代码适用于纯PHP版本。我不知道为什么这个header()部分不能在这里工作,可能是因为它的输出被重定向到了div?
为了说明问题,我的问题是:“为什么$.post(...)没有调用PHP文件,而$(”#export_div“).load(...)调用了?”.
header()部分只是一个sub问题,如果忽略它也没关系。
顺晟科技:
正如Kmoser指出的那样,我做错了事情。我访问的教程站点没有一个提到$.post()根本不会返回任何结果,而我的php代码希望返回搜索结果,并将它们写入header()调用中的一个文件中。
05
2022-12
02
2022-12
02
2022-12
29
2022-11
29
2022-11
24
2022-11