jquery 的 load() 是否可以安全地刷新搜索结果?

Is jquery's load() safe for refreshing search results?

我在问自己,在选择新类别或搜索术语后,使用 jquery 的加载功能刷新我页面上的内容是否安全?

我正在编写一个带有过滤器部分的小型库存页面,您可以在其中选择不同的类别、搜索关键字等。

选择新类别后,我使用以下功能将新内容加载到正确的位置(“#listing”):

$("#load").on('click', function () {
    event.preventDefault();
    var cat = $("#category").val();
    var tag = $("#tag").val();
    $("#listings").load("template/_listing.php?cat="+cat+"&tag="+tag);
});

template/_listing.php 中的文件回显了它在 HTML..

中找到的所有内容

所以一切正常,除了一些不能用于新加载数据的样式和脚本(我想我只需要在 template/_listing.php 文件中加载脚本)。 .

Buuut 我不确定这是否是最好的方法.. 这样您还可以访问地址 templates/_listing.php?cat=bla&tag=blu 我不确定这是否合适?

我也可以尝试使用 ajax 调用,在我的脚本中获取 JSON 和 "create" 搜索结果。这样会更好吗?

我认为应该没问题,如果我使 "template/_listing.php" 足够安全,这样就没有人可以通过其他查询进入我的数据库,那么 "cat or tag" 或?

谢谢!

当然,这是安全的,这是达到目的的好方法之一。但我建议你这样做:

$("#listings").load(
"template/_listing.php?cat="+cat+"&tag="+tag,
function() {
    //put your js script here to fix those not useable
    //e.g. $("#listings .datepicker").datepicker();
});