[英]How to pass data from a html page to another?
I have two pages: 我有两页:
In the choose.html I can choose an entry from a listview. 在choose.html中,我可以从列表视图中选择一个条目。 I can click on such entries in the listview and I want to pass the ID of that entry so that I can use the ID on the html page create.html .
我可以点击列表视图中的这些条目,我想传递该条目的ID ,以便我可以在html页面create.html上使用该ID 。
ID is a number. ID是一个数字。
I have done: 我已经做好了:
When I clicked on an entry, I get the ID: 当我点击一个条目时,我得到了ID:
function postID(id) {
alert(id);
}
This functions so far. 到目前为止这个功能。
Then I tried this code with a GET on the create.html: 然后我在create.html上使用GET尝试了这段代码:
POST: POST:
function postID(id) {
$.ajax({
url: "create.html",
type: "POST",
dataType: "text",
data: id,
success: function () {
document.location.href = "create.html";
},
error: function (jqXhr) {
alert("Error");
}
});
}
GET: 得到:
try {
$.get("chooseAddress.html", function (id) {
alert(id);
});
}
catch (e) {
alert();
}
But nothing happens. 但没有任何反应。 Can you help me?
你能帮助我吗?
Thanks 谢谢
So many work for so simple problem. 这么多工作都是为了这么简单的问题 Use a hidden field or use a Session variable.
使用隐藏字段或使用Session变量。
Use create a hidden field and give value as your Id. 使用创建隐藏字段并将值作为您的ID。
<form action='create.html'> <input type='hidden' value='id'> </form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.