๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Web/JavaScript

[JavasScript] POST ๋ณด๋‚ด๊ธฐ

๋ฐ˜์‘ํ˜•

 

 

 

var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", '/comp');
const params = {'uid': uid}

//ํžˆ๋“ ์œผ๋กœ ๊ฐ’์„ ์ฃผ์ž…์‹œํ‚จ๋‹ค.
for(var key in params) {
	var hiddenField = document.createElement("input");
    hiddenField.setAttribute("type", "hidden");
    hiddenField.setAttribute("name", key);
    hiddenField.setAttribute("value", params[key]);

	form.appendChild(hiddenField);
}

document.body.appendChild(form);
form.submit();

 

 

function post_to_url(path, params, method) {
    method = method || "post"; // ์ „์†ก ๋ฐฉ์‹ ๊ธฐ๋ณธ๊ฐ’์„ POST๋กœ
 
    
    var form = document.createElement("form");
    form.setAttribute("method", method);
    form.setAttribute("action", path);
 
    //ํžˆ๋“ ์œผ๋กœ ๊ฐ’์„ ์ฃผ์ž…์‹œํ‚จ๋‹ค.
    for(var key in params) {
        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", key);
        hiddenField.setAttribute("value", params[key]);
 
        form.appendChild(hiddenField);
    }
 
    document.body.appendChild(form);
    form.submit();
}

 

์‚ฌ์šฉํ• ๋•Œ๋Š”
<a href="javascript:post_to_url('www.XXXX.com/XXXXhtml',{'type1':'aaa','type2':'bbb'})">POST๋ณด๋‚ด๊ธฐ</a>

 

 

flask์—์„œ form๋ฐ›๊ธฐ

@app.route('/post', methods=['POST'])
def post():
    value = request.form['test']
    return value

 

 

 

 

 

kanitz.tistory.com/121

 

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋งŒ์œผ๋กœ POST ๋ณด๋‚ด๊ธฐ

function post_to_url(path, params, method) { method = method || "post"; // ์ „์†ก ๋ฐฉ์‹ ๊ธฐ๋ณธ๊ฐ’์„ POST๋กœ   var form = document.createElement("form"); form.setAttribute("method", method); form.setAttrib..

kanitz.tistory.com

 

๋ฐ˜์‘ํ˜•