Home Web Front-end JS Tutorial JS method to realize page jump parameters without losing them

JS method to realize page jump parameters without losing them

Dec 03, 2016 pm 04:54 PM
js

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 = '<?php echo $list_url;?>';
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.


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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use JS and Baidu Maps to implement map pan function How to use JS and Baidu Maps to implement map pan function Nov 21, 2023 am 10:00 AM

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

Recommended: Excellent JS open source face detection and recognition project Recommended: Excellent JS open source face detection and recognition project Apr 03, 2024 am 11:55 AM

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 Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Dec 17, 2023 pm 06:55 PM

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 PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts Dec 18, 2023 pm 03:39 PM

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 create a stock candlestick chart using PHP and JS Dec 17, 2023 am 08:08 AM

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 Maps to implement map polygon drawing function Nov 21, 2023 am 10:53 AM

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 Map to implement map click event processing function Nov 21, 2023 am 11:11 AM

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 How to use JS and Baidu Maps to implement map heat map function Nov 21, 2023 am 09:33 AM

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

See all articles