0

I'm trying to give data to a internal page of a jquery mobile app with the Get method. The app is written as a one-page solution.

If a user clicks on send I change the href of the a for example to:

$("#send_loc").on("click", function () {
    var shop = $("#shop").prev("form").find("input").val();
    var city = $("#city").prev("form").find("input").val();

    $('#send_loc').attr("href", "#search?city="+city+"&shop="+shop); 
});

On the other side I try to catch the data with:

$( document ).on( "pageinit", "#search", function() {
   var shop = getParameterByName("city");
   var city_name = getParameterByName("shop");

});

but I get no results with this.

The reason why I try to do this is, to fix the data-rel="back" button.

If a user clicks on send I generate a listview with the search parameters city and shop. But after the user clicks on a entry of the listview and goes back again to the list view the list is empty. So thats why I try to save the parameters in the URL and create the listview with the URL parameters.

thanks for any help

Kingalione
  • 4,237
  • 6
  • 49
  • 84
  • 1
    You can use this http://stackoverflow.com/questions/20974092/jquery-mobile-remember-variable-of-page-before/20977698#20977698 to retrieve the clicked link and then do whatever you want with it. If you need clarification, let me know. – Omar Feb 28 '14 at 11:04
  • Yes I'd need more clarification please. I did not really understand how to use it. – Kingalione Feb 28 '14 at 11:28
  • You want to retrieve value of input previous to clicked button, right? – Omar Feb 28 '14 at 11:48
  • 1
    check this demo http://jsfiddle.net/Palestinian/g5Umg/ if this is what you want, I'll add a detailed answer. – Omar Feb 28 '14 at 12:15
  • almost. After the user searches city and shop he gets a listview of the entries which are loaded per ajax call. Then the user clicks on one of the entries and gets a page with infos to the entry. So now if the user hits the back button he goes to #search again but without any input. Like in this example: http://jsfiddle.net/g5Umg/3/ – Kingalione Feb 28 '14 at 12:42
  • In this case, add value to back button as an attribute and retrieve it on `navigate` event along with `pagebeforechange` http://stackoverflow.com/questions/18211984/how-to-control-back-button-event-in-jquery-mobile/18213393#18213393 – Omar Feb 28 '14 at 12:49

1 Answers1

1

If it is an internal page I assume, that you are using single .js file. If so, there is no need in passing data. Just make a global variable (outside any functions) and store there your values.

OR

Have you considered caching your list page?

OR

Have you tried local storage? Here are some examples of using:

localStorage.removeItem("item");
localStorage.setItem("item", yourdata);
localStorage.getItem("item");
localStorage.clear();
Piotr Krysiak
  • 2,815
  • 3
  • 23
  • 35
  • yes I tried with local storage but it does not worked. the two functions are in seperate – Kingalione Feb 28 '14 at 10:47
  • Well I put the scripts together and used the localStorage and I get data from their too, but if I click to back after I entered a entry of the list view it still shows my a blank page. It seems that the code cant enter $( document ).on( "pageinit", "#search", function() {}); after I click on the back button – Kingalione Feb 28 '14 at 11:03
  • LocalStorage is independent from scipts. Try to remove data-rel="back" in your back button and instead of it add onclick event with mobile.changePage to your list's page. It should invoke pageinit event and fix your problems – Piotr Krysiak Feb 28 '14 at 12:20