Home > Web Front-end > JS Tutorial > body text

JS method to realize page jump parameters without losing them

高洛峰
Release: 2016-12-03 16:54:56
Original
1421 people have browsed it

The example in this article describes the JS method to achieve page jump parameters without losing them. Share it with everyone for your reference, the details are as follows:

Requirements: After editing the page, return to the list page, the parameters are not lost, and the number of pages and filter conditions can be remembered.

I firmly believe that no matter whether it is a white cat or a black cat, the one that can catch mice is a good cat. Of course, it is best if it can be handled efficiently and simply.

My idea is to pass the list page address as a parameter.

You will face a problem here. The url itself is composed of multiple parameters. If it is passed purely like this, problems will occur and the parameters will be lost.

So the url must be encrypted.

escape(), encodeURI(), encodeURIComponent()

There are three functions in JavaScript that can encode strings, namely: escape, encodeURI, encodeURIComponent, and the corresponding three decoding functions: unescape, decodeURI, decodeURIComponent.

escape() except ASCII letters, numbers and specific symbols, escapes all the incoming strings, so if you want to encode the URL, it is best not to use this method. And encodeURI() is used to encode the entire URI, because the legal characters in the URI will not be encoded and converted. The encodeURIComponent method should be the most commonly used when encoding a single URIComponent (referring to request parameters). It can escape Chinese and special characters in the parameters without affecting the entire URL.

After testing, it was found that the encodeURIComponent method can solve this problem very well.

1. Set the url

// 设置当前url
var list_url = '/document/order/default.php?page=' + page_nums + '&'+ $("#form1").serialize();
var e_list_url = encodeURIComponent(list_url);
$("#list_url").val(e_list_url);
Copy after login

2. Pass the url

var list_url = $('#list_url').val();
window.location.href='/document/order/view.php?order_id='+order_id+'&action=edit&handler=admin&list_url='+list_url;
Copy after login

3. Parse the url and jump

var list_url = &#39;<?php echo $list_url;?>&#39;;
d_list_url = decodeURIComponent(list_url);
window.location.href = d_list_url;
Copy after login

This can be achieved without losing the parameters. The main ones are page numbers and filter conditions.


Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!