zoukankan      html  css  js  c++  java
  • js 提交表单添加csrf

    function post(path, shipmentMap, method) {
        method = method || "post"; // Set method to post by default if not specified.
        var token = $('meta[name="_csrf"]').attr('content');
        var tokenName = $('meta[name="_csrf_header"]').attr('content');
        console.log(token);
        // The rest of this code assumes you are not using a library.
        // It can be made less wordy if you use one.
        var form = document.createElement("form");
        form.setAttribute("method", method);
        form.setAttribute("action", path);
    
    
        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", "requestMap");
        hiddenField.setAttribute("value", JSON.stringify(shipmentMap));
    
        form.appendChild(hiddenField);
        
        var csrfField = document.createElement("input");
        csrfField.setAttribute("type", "hidden");
        csrfField.setAttribute("name", "_csrf");
        csrfField.setAttribute("value", token);
    
        form.appendChild(csrfField);
    
    
        document.body.appendChild(form);
        form.submit();
    }
    

      

  • 相关阅读:
    185. [USACO Oct08] 挖水井
    JavaEE Tutorials (9)
    vjudge A
    HDU 2089 不要62
    国庆 day 2 下午
    国庆 day 2 上午
    国庆 day 1 下午
    P2899 [USACO08JAN]手机网络Cell Phone Network
    洛谷 P1690 贪婪的Copy
    洛谷 P2209 [USACO13OPEN]燃油经济性Fuel Economy
  • 原文地址:https://www.cnblogs.com/ly-radiata/p/6400364.html
Copyright © 2011-2022 走看看