How to read the post request parameters using JavaScript

后端 未结 18 1173
自闭症患者
自闭症患者 2020-11-22 16:41

I am trying to read the post request parameters from my HTML. I can read the get request parameters using the following code in JavaScript.

$wnd.location.sea         


        
18条回答
  •  心在旅途
    2020-11-22 17:20

    \n";
    }
    ?>
    
    

    Or use it to put them in an dictionary that a function could retrieve:

    \n"; // Implode array, javascript will interpret as dictionary
    }
    ?>
    
    

    Then in JavaScript:

    var myText = post['text'];
    
    // Or use a function instead if you want to do stuff to it first
    function Post(variable) {
      // do stuff to variable before returning...
      var thisVar = post[variable];
      return thisVar;
    }
    

    This is just an example and shouldn't be used for any sensitive data like a password, etc. The POST method exists for a reason; to send data securely to the backend, so that would defeat the purpose.

    But if you just need a bunch of non-sensitive form data to go to your next page without /page?blah=value&bleh=value&blahbleh=value in your url, this would make for a cleaner url and your JavaScript can immediately interact with your POST data.

提交回复
热议问题