Last active
July 3, 2019 14:02
-
-
Save meftunca/1d2278500f5749fcfc7948e8cafed7b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="path/to/server/script" method="post" id="my_form"> | |
<label>Name</label> | |
<input type="text" name="name" /> | |
<label>Email</label> | |
<input type="email" name="email" /> | |
<label>Website</label> | |
<input type="url" name="website" /> | |
<button type="submit" class="submit_button">Submit Form <button/> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#my_form").submit(function(event) { | |
event.preventDefault(); //prevent default action | |
var formElement = $(this); | |
var button = $(".submit_button"); | |
var post_url = formElement.attr("action"); //get form action url | |
var request_method = formElement.attr("method"); //get form GET/POST method | |
var form_data = new FormData(formElement[0]); //Creates new FormData object | |
button.attr("disabled", true); // Burada disabled ataya bilirsiniz | |
button.text("İstek Gönderiliyor"); // Burada disabled ataya bilirsiniz | |
// üstteki veri | |
$.ajax({ | |
url: post_url, | |
type: request_method, | |
data: form_data, | |
contentType: false, | |
cache: false, | |
processData: false | |
}) | |
.done(function(response) { | |
// burası işlem tamamlandığında çalışacak | |
if(response === true || response === 1){ | |
document.getElementById("myForm").reset() | |
}else{ | |
alert("hata oluştu") | |
} | |
console.log("başarılı"); | |
}) | |
.fail(function() { | |
// hata gelirse | |
console.log("hata"); | |
}) | |
.always(() => { | |
// işlemler bittiğinde en son çalışacak alan | |
button.attr("disabled", false); // Burada disabled ataya bilirsiniz | |
button.text("Gönder"); // Burada disabled ataya bilirsiniz | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment