php - 提示时 Ajax 不执行新请求
问题描述
我仍在学习 Ajax,每次我想使用 ajax 更改页面内容时,我都会使用以下脚本:
function load_page(id)
{
$.ajaxSetup({ cache: false });
var toId = "";
$('#ajax-intro-body').show();
if (id == "dashboard")
toId = "../src/pages/partials/" + id + ".php";
else
toId = "../src/pages/" + id + ".php";
$.ajax({
url:toId,
method:"POST",
cache: false,
headers: { "cache-control": "no-cache" },
data:{},
success:function(data)
{
if (data == "session_expired"){
location.replace("../src/pages/login/")
}else{
// Show output data
$('#ajax-content').html(data);
// Set refresh address id
$('.refresh-content').attr('id',id);
// Fade out the loading bar body
$('#ajax-intro-body').fadeOut(100);
// Remove animation from sync
$('#refresh-icon').removeClass("fa-spin");
}
}
});
}
所以我认为代码很容易理解。现在我有一个“项目页面”,你也可以在其中删除它,这个页面正在使用上面的脚本加载,我在 php 中得到了以下代码:
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (isset($_GET['id'])){
$("#dialog-3").dialog({
autoOpen: false,//remove this and the click to aut open
bgiframe: true,
width: 340,
modal: true,
resizable: false,
buttons: {
"Delete":function(){
$(this).dialog("close");
$.ajax({
type: "POST",
url: "../src/requests/deleteproject.php",
data: {
id: <?php echo $projectid; ?>,
flag: true,
},
success: function (data) {
load_page('projects/listprojects');
}
});
},
Cancel: function() {
$(this).dialog("close");
}
}
});
}
}
因此,如果我想删除它,您可以看到我正在尝试在项目页面中执行和 ajax 请求。使用浏览器网络选项卡,我可以看到,当我调用项目页面时,实际上 GET 参数 id 正在更改为正确的数字,但实际上它并没有更新 ID id: <?php echo $projectid; ?>,
。我读过我需要在ajax请求中将缓存设置为false,但它似乎不起作用,所以我无法更新Id。
你们有什么想法吗?谢谢你!
解决方案
推荐阅读
- netsuite - 在 netsuite 高级 pdf 模板中设置 bg 图像大小
- python - 从模式匹配和替换
- android - Facebook 登录 GraphResponse 错误 Android
- html - 为什么我不能用定位移动我的一些桌子?
- excel - 对于下一个循环(初学者)
- opencv - 一个关于3D空间中相机坐标变换的问题
- javascript - 如何在每次刷新时更改选取框标签中的文本颜色
- php - 如果否,是否可以在数据库中发送查询。的喜欢超过 50
- spring - 为什么我的映射 DTO 列表为空?映射和持久化子列表的最佳方式是什么?
- c# - Visual Studio 2017 清理/关闭脚本