Access GET directly from JavaScript?

前端 未结 7 1248
南旧
南旧 2020-11-27 20:59

I suppose I could use PHP to access $_GET variables from JavaScript:



        
相关标签:
7条回答
  • 2020-11-27 21:52

    i use this one for Get request (like $_GET in php):

      var urlParams;
      (window.onpopstate = function () {
        var match,
              pl     = /\+/g,  Regex for replacing addition symbol with a space
               search = /([^&=]+)=?([^&]*)/g,
              decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
               query  = window.location.search.substring(1);
           urlParams = {};
           while (match = search.exec(query))
            urlParams[decode(match[1])] = decode(match[2]);
        })();
    
    0 讨论(0)
提交回复
热议问题