简体   繁体   English

如何将数据从html页面传递到另一个页面?

[英]How to pass data from a html page to another?

I have two pages: 我有两页:

  • choose.html choose.html
  • create.html create.html上

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.

相关问题 如何将数据从一个页面传递到另一个页面html - How to pass data from one page to another page html 如何在html中将数据从一个页面传递到另一个页面? - How to pass data from one page to another page in html? 如何将数据从一个html页面传递到另一个? - How to pass data from one html page to another? 在angularJS中将数据从一个html页面传递到另一个html页面 - Pass data from one html page to another html page in angularJS 如何使用JQuery将数据从一个HTML页面传递到另一HTML页面? - How to pass data from one HTML page to another HTML page using JQuery? 如何仅使用JavaScript将表单数据从一个HTML页面传递到另一HTML页面? - How do I pass form data from one HTML page to another HTML page using ONLY javascript? 如何使用Phonegap中的JavaScript将数据从一个html传递到另一个html页面? - How to pass the data from one html to another html page using JavaScript in Phonegap? 如何将数组从一个HTML传递到另一个HTML页面? - how to pass an array from one html to another html page? 如何使用 JavaScript 将数据从一个 HTML 页面传递到另一个页面 - How can i pass data from one HTML page to another using JavaScript 如何使用JavaScript将列表组之类的数据从一个HTML页面传递到另一HTML页面? - How can I pass data like list group from one html page to another using JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM