get请求中url可能一些参数带有一些包含?或者&的连接符,需要做如下处理

 %26代替&, %3F代替?

接受页面不需要改动任何,

 &的asc码为%26. ?的asc码为%3F.

如:

'/ledgers/1/edit?back=/ledgers?year=2018&month=5';

  我们想传递back为/ledgers?year=2018&month=5直接这样写,后台接收到的back为/ledgers?year=2018

而不是/ledgers?year=2018&month=5

所以将原url变为

'/ledgers/1/edit?back=/ledgers%3Fyear=2018%26month=5';
  # ruby写法
  require 'uri'

  URI.encode("Hello there world")
  #=> "Hello%20there%20world"
  URI.encode("hello there: world, how are you")
  #=> "hello%20there:%20world,%20how%20are%20you"
  URI.decode("Hello%20there%20world")
  // javascript写法
  var encoded = encodeURIComponent(str);
0条评论 顺序楼层
请先登录再回复