Created
          June 26, 2021 01:14 
        
      - 
      
 - 
        
Save pweinzettel/8dcf3d8c261b688196d1f65825a0db75 to your computer and use it in GitHub Desktop.  
    redirect and post json data using forms
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function post(url, data) { | |
| var form = $(document.createElement('form')); | |
| $(form).attr("action", url); | |
| $(form).attr("method", "POST"); | |
| $(form).prop("hidden", true); | |
| for (const key in data) { | |
| var input = $("<input>") | |
| .attr("type", "text") | |
| .attr("name", key) | |
| .val(data[key]); | |
| $(form).append($(input)); | |
| } | |
| form.appendTo(document.body); | |
| $(form).submit(); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment