LoginSignup
2
2

More than 5 years have passed since last update.

JavaScript からの HTTP Request で . と - を Percent-encoding する方法

Last updated at Posted at 2015-01-14

%%25 にする感じ。

%2D -> %252D
%2E -> %252E

NG

%2D%2E-. に変換されて Request されてしまう。

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title> - . </title>
  <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
  <script type="text/javascript">
    $(function(){
        $.ajax({
          type: 'post',
          url: '/hahaha/%2D%2E',
          data: {
          },
          success: function(data){
            console.log(data);
          }
        });
    });
  </script>
</head>
<body>
hoge
</body>
</html>

OK

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title> - . </title>
  <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
  <script type="text/javascript">
    $(function(){
        $.ajax({
          type: 'post',
          url: '/hahaha/%252D%252E',
          data: {
          },
          success: function(data){
            console.log(data);
          }
        });
    });
  </script>
</head>
<body>
hoge
</body>
</html>
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2