TIL 200227

조양권·2021년 5월 17일

TIL

목록 보기
6/24

1. 오늘

html에서 form형식을 사용해 서버로 querystring을 전달해 url을 분기별로 나누는 작업에 진척이 생겼다.

<form action="/sell_page" method="get">
   <input name="platform" type="submit" value="steam"></input>
   <input name="platform" type="submit" value="uplay"></input>
   <input name="platform" type="submit" value="GOG.com"></input>
</form>

메인 url

클릭시 url

해당 페이지(/sell_page)에서 querystring으로 받은 parameter을 가져오는 함수를 코딩했다.

function get_query_string_object() {
    var a = window.location.search.substr(1).split('&');
    if (a == "") return {};
    var b = {};
    for (var i = 0; i < a.length; ++i) {
        var p = a[i].split('=', 2);
        if (p.length == 1)
            b[p[0]] = "";
        else
            b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
    }
    return b;
}
var params = get_query_string_object();
var platform = params.platform; # 최종결과값(platform의 value)
console.log(platform)

로그로 정상수행하는지 확인

이후 flask에서 api를 분기별로 나누어 html 내부에서 현재의 페이지에 맞는 api를 호출할수 있도록 진행할 수 있게 됐다.

profile
할 수 있는 것이 늘어나는 즐거움

0개의 댓글