user3679607
user3679607

Reputation: 163

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. 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 is a number.

I have done:

When I clicked on an entry, I get the ID:

function postID(id) {
    alert(id);
}

This functions so far.

Then I tried this code with a GET on the create.html:

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

Upvotes: 1

Views: 73

Answers (2)

sravan kumar
sravan kumar

Reputation: 66

Use create a hidden field and give value as your Id. <form action='create.html'> <input type='hidden' value='id'> </form>

Upvotes: 1

FMQB
FMQB

Reputation: 673

So many work for so simple problem. Use a hidden field or use a Session variable.

Upvotes: 2

Related Questions