JQuery transfers data between pages

I am new to jQuery. Is there a way to get the booked value on another page via jQuery?

 $(document).ready(function() { $(".active").click(function() { var booked=$(this).val(); confirm(booked); }); }); 
+4
source share
4 answers

Use a cookie or HTML5 localStorage if it is exclusively client-side.

 localStorage.setItem('bookedStatus' + customerId, true); 

Just use ajax if the data is already sent to the server.

 $.get('/site/getBookingStatus?customerId=' + customerId, function(data){ alert(data); }); 
+6
source

Alternatively, if this is a simple string, you can add the URL of the page while navigating to another page. If this is protected data, you can encrypt the string and attach.

Your URL will look like this: example.com/nextPage?x=booked

On the next page, you can get the string by decrypting it as indicated:

 var encodedData = window.location.href.split('=')[1]; var bookedValue = decodeURI(encodedData); 

If you have encrypted the script, you need to decrypt on the next page.

+2
source

You can try cookies if they are in the same domain.

You will need to use the jQuery cookie plugin (to fix browser issues).

You should try to do something like this:

  • Create the variable on page 1.
  • Save this variable as a session cookie.
  • On page 2, you can access the session cookie.
  • If the user directly visited page 2 without visiting page 1, you should set the default value.
  • Done!
0
source

localStorage does not work in mobile browsers. I gave up trying to get localStorage to work on iPhone / Safari. If you don’t transfer too much data, then the simple solution is to bind the data to the URL you are accessing using the usual syntax ? Param = :

 // set your data in the source page function set_url_data(go_to_url, data) { new_url = go_to_url + '?data=' + data; window.location.href = new_url; } // parse your data in the destination page function grab_data_from_url() { url = window.location.href; data = url.split('data=').pop(); return(data) } 
0
source

All Articles