개발 공부

타임리프 자바스크립트 사용하기, 데이터 내보내기 본문

자바, 스프링, 웹개발/웹개발

타임리프 자바스크립트 사용하기, 데이터 내보내기

아이셩짱셩 2021. 1. 6. 20:47

  1. 데이터 js에서 사용하기

if($("#message").val() != ""){}
<input th:value="${message}" type="text" id="message" hidden="true"/>

   2. 데이터 보내기

$("#submit").click(function(){ 
	var serialNumber = $("#serialNumver").val(); 
    $.ajax({ 
    	url: "localhost:8070/v1/api/manufacture-info/serial", 
        type : "POST", 
        contentType : "application/json;charset=UTF-8", 
        dataType : "json", 
        data : "{\\"serialNumber\\" : serialNumber }", 
        success : function(response){ } 
    }); 
});

오류)

Access to XMLHttpRequest at 'localhost:8070/v1/api/manufacture-info/serial' from origin 'http://localhost:8070' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.

https://velog.io/@takeknowledge/로컬에서-CORS-policy-관련-에러가-발생하는-이유-3gk4gyhreu

'자바, 스프링, 웹개발 > 웹개발' 카테고리의 다른 글

랜덤 알파벳 생성  (0) 2021.06.18
Exception class의 ResponseStatus 사용  (0) 2021.01.14
자바 개발 참고  (0) 2021.01.06
잡다한 기술  (0) 2021.01.06
html submit 꼼수 js에서 form 만들기  (0) 2020.12.28
Comments