Last active
August 29, 2015 14:26
-
-
Save cagataycali/08dcd81bb81ab0889078 to your computer and use it in GitHub Desktop.
jQuery & Ajax
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
{# Yeni Ödev Ekleme Formu #} | |
<form action="{{ path('ekle') }}" data-parsley-validate name="form-odev-ekle" id="form-odev-ekle" method="post" onsubmit="return false"> | |
<div id="yeni_odev_kutusu"> | |
<div class="row"> | |
<div class="col-md-6"> | |
<div class="form-group"> | |
<label>Soru Bankası</label> | |
<input name="soru-bankasi-adi" type="text" class="form-control" placeholder="Soru Bankasının Adını Giriniz"> | |
</div> | |
</div> | |
<div class="col-md-6"> | |
<div class="form-group"> | |
<label>Soru Sayısı</label> | |
<input name="soru-sayisi" type="number" class="form-control" placeholder="Soru sayısını giriniz"> | |
</div> | |
</div> | |
</div> | |
<div class="form-group"> | |
<label>Konu</label> | |
<input name="konu" id="konu" type="text" class="form-control" placeholder="Çözülen soruların konusunu giriniz."> | |
</div> | |
<div class="form-group"> | |
<label>Açıklama:</label> | |
<textarea name="aciklama" class="form-control" ></textarea> | |
</div> | |
</div> | |
</form> | |
<button id="odev-ekle" class="btn btn-success kaydet"><i class="fa fa-check"></i> Ödev Eklemeyi Tamamla</button> |
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
<script> | |
/** | |
* Ekleme | |
*/ | |
$(document).off('click','.kaydet').on('click','.kaydet', function (e) { | |
// Kaydet class'ına sahip nesnenin id değerini al. | |
var action = $(this).attr('id'); | |
// soru-form diye bir nesne elde ettik. Başına #form ekleyelim ve artık bu formu niteliyor. | |
var a = $('#form-'+action); | |
$.ajax({ | |
url: a.attr('action'), | |
data: a.serialize(), | |
type: 'post', | |
dataType: 'json', | |
success: function(response) { | |
$('#ajax-'+action).fadeToggle("slow").html('ts'); | |
alert('basarili'); | |
}, | |
error: function() { | |
$('#ajax-'+action).fadeToggle("slow").html('ts'); | |
} | |
}); | |
e.preventDefault(); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment