0

I want to send json object from page 1 to page 2 without server interaction what i have tried so far is like this

from page 1 i have this code

url = '../reports/page2.php?basicinfo=' + encodeURIComponent(JSON.stringify(basicinfo));
window.open(url + "&month=" + month, '_self');

in page two i acces the data by getting the object from the url. But i had a problem. I exceeded the The requested URL's length exceeds the capacity limit for this server. So i wanted to try if it is possible using ajax what i have tried is

var url = '../reports/page2.php; var basicinfo = JSON.stringify(basicinfo)

$.ajax({
    type: 'POST',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    data: {
        action: "page2",basicinfo:'basicinfo '

    },
    complete: function() {
        window.location = url;
    }
}); 

I was directed to the correct page my problem is i cant get the data now.

Brownman Revival
  • 3,620
  • 9
  • 31
  • 69

3 Answers3

1

For this purpose You can use localstorage save your json in localstorage variable and fetch it at any moment

localStorage.setItem('favoriteflavor','vanilla'); /*how to save data in localstorage*/
var taste = localStorage.getItem('favoriteflavor');/*how to fetch data from localstorage*/
alert(taste);
localStorage.removeItem('favoriteflavor');/*how to delete data from localstorage*/

For more details click here

So save all your json in localstorage variable before

window.location = url;

in your ajax complete section and fetch localstorage data after redirection (i.e. on this page url )

If you don't want to use jquery variable for data security. Then the only possible way is by using cookies. Here is the link on stack from where you can see how to create cookies using jquery how to save data in a cookie using jquery

Community
  • 1
  • 1
PHP Worm...
  • 4,109
  • 1
  • 25
  • 48
0

Try to write this to a file and read from the popup. http://php.net/manual/en/function.file-put-contents.php http://php.net/manual/en/function.file-get-contents.php

Tismon Varghese
  • 849
  • 1
  • 6
  • 17
0

HTTP is stateless protocol. When you redirected to another page - it is new request and data from previous page will be lost. To share data between pages need to store data (from first ajax request), e.g in session, and restore data from session on second page.

Constantine
  • 482
  • 3
  • 10