๐ŸŒธ [SPRING BOOT] | ์‹œํ๋ฆฌํ‹ฐ & AJAX - get๋ฐฉ์‹์˜ fetch๊ฐ€ ์•ˆ๋œ๋‹ค๋ฉด, header ์ ์šฉํ•ด๋„ ์•ˆ๋œ๋‹ค๋ฉด

0
post-thumbnail

๐ŸŸฆ get๋ฐฉ์‹์˜ fetch๊ฐ€ header ์ ์šฉํ•ด๋„ ์•ˆ๋œ๋‹ค.

๐Ÿ”น ์—๋Ÿฌ

  • get๋ฐฉ์‹์˜ fetch๊ฐ€ ์•ˆ๋œ๋‹ค
  • header ์ ์šฉํ•ด๋„ ์•ˆ๋œ๋‹ค

๐Ÿ”น ์›์ธ & ํ•ด๊ฒฐ

โœ… ํ•ด๋‹น ๊ฒฝ๋กœ๋ฅผ ์ •ํ™•ํ•˜๊ฒŒ ์‹œํ๋ฆฌํ‹ฐ์— permitAll์ด๋‚˜ ignoring์— ๋„ฃ์–ด์ค˜์•ผ ํ•œ๋‹ค.

security

        http.authorizeRequests()
                .antMatchers("/whygram","/user/join", "/user/auth", "/user/emailCheck/*").permitAll()
                .anyRequest().authenticated();
controller

    @ResponseBody
    @GetMapping("/emailCheck/{users_email}")
    public Map<String, Integer> emailCheck(UserEntity param, @PathVariable String users_email) {
        System.out.println(users_email);

        param.setUsers_email(users_email);
        Map<String, Integer> data = new HashMap();
        int result = service.selEmail(param);
        data.put("result", result);
        return data;
    }

๐ŸŸฆ templetInputException

๐Ÿ”น ์—๋Ÿฌ๋ฉ”์‹œ์ง€

templetInputException

๐Ÿ”น ์›์ธ & ํ•ด๊ฒฐ

โœ… @responsebody๋ฅผ ๋„ฃ์–ด์ค˜์•ผ ํ•œ๋‹ค.

js

function emailCheck() {
    joinEmailElem.value = completeEmail();
    const users_email = joinEmailElem.value;
    console.log(users_email);

    if (!isvalid(emailIdElem, emailExp) || !isNotEmpty(emailAdrsElem)) { return; }

    fetch('/user/emailCheck/' + users_email)
        .then(res => res.json())
        .then(myJson => {
            console.log(myJson);
          if(myJson.result == 0) { //์ค‘๋ณต๊ฒ€์‚ฌ ํ†ต๊ณผ
              ok(emailIdElem, "์‚ฌ์šฉ๊ฐ€๋Šฅํ•œ ์ด๋ฉ”์ผ์ž…๋‹ˆ๋‹ค. ์ด๋ฉ”์ผ ์ธ์ฆ์ด ํ•„์š”ํ•œ ์  ์œ ์˜ํ•ด ์ฃผ์„ธ์š”.");
          } else { //์•„์ด๋”” ์ค‘๋ณต๋จ
              warn(emailIdElem, "์ค‘๋ณต๋œ ์ด๋ฉ”์ผ์ž…๋‹ˆ๋‹ค.");
          }
    });
}
controller

    @ResponseBody
    @GetMapping("/emailCheck/{users_email}")
    public Map<String, Integer> emailCheck(UserEntity param, @PathVariable String users_email) {
        System.out.println(users_email);

        param.setUsers_email(users_email);
        Map<String, Integer> data = new HashMap();
        int result = service.selEmail(param);
        data.put("result", result);
        return data;
    }
profile
๋ช‡ ๋ฒˆ์„ ๋„˜์–ด์ ธ๋„ ์•ž์œผ๋กœ ๊ณ„์† ๋‚˜์•„๊ฐ€์ž

0๊ฐœ์˜ ๋Œ“๊ธ€