JS method to realize page jump parameters without losing them
Dec 03, 2016 pm 04:54 PMThe 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);
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;
3. Parse the url and jump
var list_url = '<?php echo $list_url;?>'; d_list_url = decodeURIComponent(list_url); window.location.href = d_list_url;
This can be achieved without losing the parameters. The main ones are page numbers and filter conditions.

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use JS and Baidu Maps to implement map pan function

Recommended: Excellent JS open source face detection and recognition project

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts

How to create a stock candlestick chart using PHP and JS

How to use JS and Baidu Maps to implement map polygon drawing function

How to use JS and Baidu Map to implement map click event processing function

How to use JS and Baidu Maps to implement map heat map function
