Reputation: 55
I am new to jQuery. Is there any way to retrieve the value of booked
in another page through jQuery?
$(document).ready(function() {
$(".active").click(function() {
var booked=$(this).val();
confirm(booked);
});
});
Upvotes: 6
Views: 13254
Reputation: 13334
localStorage doesn't work well on mobile browsers. I've given up on trying to get localStorage to work on iPhone/safari. If you're not passing too much data then a simple solution is to attach the data to the url you are navigating to, using the usual ?param= syntax:
// 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)
}
Upvotes: 2
Reputation: 1258
Alternatively, if this is a simple string you can append with the URL of the page while navigating to another page. If this is secured data, you can encrypt the string and attach.
Your URL will be : example.com/nextPage?x=booked
In the next page you can get the string by decoding it as given :
var encodedData = window.location.href.split('=')[1];
var bookedValue = decodeURI(encodedData);
If you have encrypted the script, you have to decrypt in the next page.
Upvotes: 3
Reputation: 23044
Use cookies or HTML5 localStorage
if its purely on the client-side.
localStorage.setItem('bookedStatus' + customerId, true);
Else use ajax if the data has already been submitted to server.
$.get('/site/getBookingStatus?customerId=' + customerId, function(data){
alert(data);
});
Upvotes: 7
Reputation: 11431
You could try cookies if it is on the same domain.
You'll need to use the jQuery cookie plugin (to iron out cross browser issues).
You should try to do something like this:
Upvotes: 0