页面加载后剥离查询字符串
strip query string after page load
im正在开发php和我的网页URL如下
http://localhost/myweb/?action=news
http://localhost/myweb/?action=my_profile
http://localhost/myweb/?action=my_upload
http://localhost/myweb/?action=my_collection
http://localhost/myweb/?action=chat
http://localhost/myweb/?action=my_friends
etc
例如,在特定页面中,有访问href链接的删除功能
http://localhost/myweb/?action=my_friends&delete=2414535435 <-friends id
我这样做是为了让它整洁,让链接在不看源的情况下看不到
a href='#'
并使用javascript访问真实链接
$('.deleteclass').on('click', function () {
var name= $(this).attr('nameattr');
if(confirm('You sure want to delete '+name+'?')){
window.location='?action=my_friends&delete='+this.id;
}
});
问题是,在我处理了删除和加载页面后,我不希望地址栏上有完整的链接。
http://localhost/myweb/?action=my_friends&delete=2414535435
我需要在地址栏上把它做回这个样子
http://localhost/myweb/?action=my_friends
有可能吗?也许通过mod重写?
浏览器加载页面后,不能剥离url。
只需在删除或执行其他操作后重定向即可。
header('Location: /myweb/?action=my_friends');
将错误/成功消息添加到会话变量中(在执行标头之前的操作脚本中),这样您就可以在其他页面上显示它们
$_SESSION['errors'] = "Delete Failed: For Some Reason";
在其他页面上,检查会话变量是否存在,显示它,然后删除它(否则它将停留在那里,页面将继续认为存在错误)
<?php
if(isset($_SESSION['errors'])) {
//Do some code to show the error
...
unset($_SESSION['errors']); //delete the error messages
}
相关文章:
- 如何有效地将游戏数据存储在URL查询字符串中
- 从查询字符串参数推断出正确的数据类型
- AngularJS:获取链接中没有哈希的查询字符串值
- AngularJS,如何更改查询字符串
- 如何将activeadmin查询字符串传递给batch_action
- 如何从查询字符串中的输入字段发回文本
- Django在使用AJAX时没有接收到新的查询字符串
- 使用查询字符串方法清除浏览器缓存
- 用于刷新的Javascript更改查询字符串
- 我想将查询字符串变量添加到JSON名称/值对中
- 将查询字符串值从页面传递 asp.net 到 iframe
- jqueryajax生成查询字符串,如果未定义则不通过
- 如何将查询字符串传递到HTML框架
- AngularJs将查询字符串发布到c#控制器
- Jquery - 从查询字符串中获取“#”值之后,而不是在“?”符号值之后获取
- 在 JavaScript 中将查询字符串传递给 Web 服务 (ASP.NET)
- 在查询字符串中查找 where 子句
- POST encodeURI查询字符串内部服务器错误 500
- JavaScript:从具有使用 # 符号的路由的 URL 获取查询字符串
- 更改链接 URL 中的路径名,同时保持查询字符串不变