How to pass variables between PHP pages via Javascript?

Asked

Viewed 1,002 times

7

I was doing a search in PT and EN on how to pass variables from one page to another via Javascript, although I found a lot of information continued with the doubt of which is the best way to do it.

I have some fields of a table (paginated) with filter, via Javascript that filters according to the elements present in the same table. But when I pass page the filter I used is deleted because it is called again my script filter.

I want to keep the filter active in the table even changing page.

My question is different from Simple paging in jQuery/Javascript, because I already have paging, I already have filters, I already have everything working. Only every time I change page the filter disappears. How to pass my filter variables to the other page to be used in my script filter?

1 answer

5


Three ways to do this:

  • Pass the filter through Ajax to the server, and save to the session for later use

  • Save the filter to a cookie generated and consumed by Javascript

  • Store the filter in the localStorage (less supported, does not work on older browsers)

Except for the compatibility problem of localStorage, the three solutions seem to me equally good. Use the one that has more affinity with the code you already have.

  • That’s the problem, the page is aimed at people who may have old browsers and cookies disabled. How much the first option would not affect performance when many users are logged in?

  • 1

    Look, you don’t have many other options if you can’t trust client-side storage (in the browser itself). It is Session, database or file system. And you need to pass this information to the server. But there should be so many requests so, even with many users, I doubt that they will all be ordering the table at the same time, most should stay in the pattern.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.