NO。停止使用#进行数据传输。让jQM做它的事情。不要打扰它。使用查询字符串(在url中添加?)。 我的建议是停止使用查询字符串(?标签)和#标签将数据发送到下一页。使用localStorage
处理它。它比查询字符串更安全,因为用户不会看到URL更改,所以您的敏感数据至少在一定程度上是隐藏的。 localStorage
是HTML5的API,它就像是每个域预留的临时存储空间。这些数据将一直持续到缓存中的数据被清除。假设你有一个锚标记都到dowork.html,
<a href="doWork.html" data-role="button">Go to Do work</a>
的设备ID添加属性的标签本身,就像这样:
<a href="doWork.html" data-deviceid="10" data-role="button">Go to Do work</a>
你会动态地这样做,你可能也以同样的方式使用它。你明白了吗?
这个click事件是这样的:
$(document).on("click", "a", function(e) //use a class or ID for this instead of just "a"
//prevent default
e.preventDefault();
//get device id from tag attribute
var deviceId = $(this).data("deviceid");
//set it in localStorage
localStorage["dId"] = deviceId;
//redirect
$.mobile.changePage(this.href);
});
然后,在其他页面的pageinit
(或任何事件),得到存储设备ID和发送Ajax调用服务器。
//assuming #dowork is the id of a div with data-role="page"
$(document).on("pageinit", "#dowork", function() {
//get from storage
var deviceId = localStorage["dId"];
//make ajax call or server call with deviceId here
});
但是,如果您仍想使用此URL,look at this question。我在那里给出了足够体面的答案。
因此,你建议我正在做什么只是改变我附加的#符号?它会起作用吗?命令是一样的吗? window.location.hash.substring(1)? –
不,该命令将需要更改为此位置.search.substring(1) – user1549458