๋ชฉ์ฐจ
๋ฏธ๋์ ๋๋ฅผ ์ํด ๊ธฐ๋ก์ ๋จ๊น ๐
ajax๋ฅผ ํตํด ์ป์ด์จ ๊ฒฐ๊ณผ๋ฅผ ์ ์ฅํ๋ ค๋ฉด ajax์ ์ต์ ์ async: false๋ฅผ ์ค์ ๋๊ธฐ์์ผ๋ก ์ฒ๋ฆฌํ๋๋ก ๋ณ๊ฒฝํด์ผ ํ๋ค. ๊ธฐ๋ณธ๊ฐ์ true
์๋๋ฉด undefined๋ก return ๋๋ค.
function duplicateCheck(menuCode) {
let duplicate_result;
$.ajax({
url : '/admin/menu/duplicateCheck',
async: false,
type : 'post',
data : {'menuCode': menuCode},
success: function (data) {
// alert("data : " + data);
duplicate_result = data;
}
});
return duplicate_result;
}
Reference : https://stackoverflow.com/questions/8077443/save-response-from-jquery-ajax-function
Save response from jQuery ajax function
I've got a custom function, which calls ajax request and I'm able to save response data to variable and return it. 0 is always returned, but alert shows e.g. 3712. Here is the function: function ...
stackoverflow.com

'IT > development' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[mybatis] mybatis parameter ์ฌ๋ฌ๊ฐ ์ ๋ฌ (0) | 2022.11.22 |
---|---|
[mybatis] ์์ธ ์กฐํ ์ ๋ณต์๊ฐ ์ถ๊ฐ ์กฐํ(feat. vo & map) (0) | 2022.11.22 |
[JavaScript] submit control(feat. onsubmit) (0) | 2022.11.22 |
[spring Boot] Request method 'POST' not supported(feat. thymeleaf) (0) | 2022.11.22 |
[jQuery] jQuery.ajax() ์ฌ์ฉ๋ฒ ์์(feat. ๋๊ธ ํ์ด์ง๋ค์ด์ ) (0) | 2022.11.21 |
๋๊ธ