2
I have a search page on my system. Due to pagination I am using the form data via GET. However, when I search something the URL is, for example:
http://sistema.com/busca.php?nome=silva
Searching I found a "workaround" that after having done the search it returns the normal URL, not leaving visible to the user. I used this:
if(typeof window.history.pushState == 'function') {
window.history.pushState({}, "Hide", "http://sistema.com/busca.php");
}
At first it works, with some delay (let the user see how a flash and already changes the URL), but it works.
The problem is when I press the "Back" of the browser. It leaves the URL with the parameters again. How to resolve this browser back? There is a more elegant way to mask these parameters?
The ideal is to use the POST method, so the search is not in the URL. The History API was not made for this. Post paging is quiet, just use Hidden fields. And in the worst case, you can mix GET with POST if you need to, sending the fields with POST, but mounting Urls with parameters).
– Bacco
I was using POST, but it ended up giving some problems in the pagination. Example: when I went from the first to the second page, the query got lost, did not respect the search I was doing and returned to its initial state.
– ziad.ali
The ideal is to fix the problem, but do it the right way. Wanting to improvise usually ends up in more problems. If it didn’t work, some stage of knowledge was missing. I would suggest working harder on the POST part to have an app that won’t give you a headache in the future. At first it can be boring to solve, but it is a knowledge that will serve you for a lot of things in other situations. Understanding how to work with POST and GET is an essential thing for web applications.
– Bacco
Ok, I agree. But so, when you say, "just use Hidden fields". Isn’t that kind of field invisible to the user? How would he use?
– ziad.ali
In the field Hidden you will put the current search, and the desired page number. The field it enters will be normal, and not Hidden.
– Bacco
Why not make that request via AJAX and change only the page content?
– Sergio
@Bacco obg, I’m going to do a little research on how to do this. Sergio, honestly, because I don’t know how to haha.. Some link that could help me out?
– ziad.ali
@Ziad.ali I need to do other things now, but if I find a good reference, I’ll let you know. Master GET and POST, because these are things you’ll find all the time.
– Bacco
Beauty @Bacco was worth!
– ziad.ali
Ziad, Ajax seems difficult at first but there’s not much mystery, and after you get the hang of it, you won’t want to stop using ;)
– brasofilo
You could use the . htaccess
– KhaosDoctor
Agree with @Khaosdoctor, . htaccess you can create a rule that rewrites your URL.
– Ivan Ferrer