javascript
<form id="form">
<!-- inputs -->
<button type="submit" id="submit">
submit
</button>
</form>
<script>
$('#submit').click(function(e){
e.preventDefault();
var form = new FormData(document.getElementById('form'))
$.ajax({
url: "/api/endpoint",
data: form,
type: 'post',
processData: false, // important
contentType: false, // important
cache: false,
success: function(data)
{
console.log(data)
// redirect
window.location.replace(data.redirect);
},
error: function(data)
{
// integrate Swal to display error
Swal.close();
if (data.status == 419) {
window.location.reload();
} else {
Swal.fire({
icon: 'info',
title: 'Error',
html: data.responseJSON.message,
});
}
}
});
})
</script>
laravel server side response example
return response()->json([
'message' => 'message ...',
'redirect' => 'https://example.com/path'
], 200);
CLICKFORCE10F., No. 285, Sec. 3, Nanjing E. Rd., Songshan Dist.TEL: (02)2719-8500Fax: (02)2719-8580
Aug 13, 2024Get a Big Picture 學任何東西前,先有個 big picture 再下去逐一學習比較不會學偏。 搜尋某領域 roadmap,會有人分享這個領域的學習路徑,讓你少走冤旺路。 e.g. backend roadmap, game developer roadmap Resources CS50 哈佛的通識課,最經典是從零開始純講電腦科學,現在也有一些是搭配主題帶觀念,像是 web 或 AI。我自己只看過原始的,但搭配其他主題的看起來也不錯,你可以自己在他們 youtube 頻道挖寶。 Classic: https://www.youtube.com/watch?v=NZxALvNlF-8&list=PLhQjrBD2T383f9scHRNYJkior2VvYjpSL
Dec 25, 2022前言 這次部署踩了不少雷,像是因為專案是用 Laravel 8 寫的,所以機器也要升到 PHP7.4,但怎麼升、要裝哪些東西也是卡很久;裝好後那個權限問題也是折騰了一番,為了下次不再崩潰,紀錄個部署流程 準備 GCP Compute Engine: Ubuntu 18.04 要部署的專案 步驟
Sep 27, 2022Contains Duplicate #1 func containsDuplicate(nums []int) bool { // hash table // key -> value // if value > 1 return true idmap := make(map[int]int) // iterate through the given slice for i:=0; i < len(nums); i++ {
Sep 2, 2022or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up