[英]HTML Form with javascript not working - AJAX POST data is not sending to PHP
Javascript code: Javascript代码:
$("#musteriEkleBtn").on("click", function(){
var zp = $("#musteriEkleForm").serialize();
$.ajax({
url: "tsettings/islem.php?islem=mKayit",
type: "POST",
data: zp,
success: function(cevap){
$("#musteriEkleAlertSuccess").html(cevap).hide().fadeIn(700);
}
});
});
Html Form Example: Html 表单示例:
<form id="musteriEkleForm" method="POST">
<li>
<label>Adınız :</label>
<input placeholder="Adınızı yazın." type="text" name="musteri_isim">
<i class="zirvepin-icon zirvepin-user"></i>
</li>
<li class="zirvepin">
<input id="musteriEkleBtn" type="submit">Register</input>
</li>
</form>
This html input submit button is not working, how can I make this code work?此 html 输入提交按钮不起作用,如何使此代码起作用?
So the form data needs to access the islem.php file, but the form data does not go to islem.php.所以表单数据需要访问islem.php文件,但是表单数据不会去islem.php。
islem.php file : islem.php 文件:
if(g('islem') == 'mKayit') {
echo"<script type='text/javascript'> alert('Evet Çalışıyor'); </script>";
}
Thanks to everyone who helped me with this problem, thanks to friends who helped solve the problem via stackexchange fixed.感谢所有帮助我解决这个问题的人,感谢通过 stackexchange fix 帮助解决问题的朋友。
If you are experiencing the same problem I leave a code that works for you, and thanks to this code you will be out of trouble :如果您遇到同样的问题,我会留下一个对您有用的代码,多亏了这段代码,您将摆脱困境:
$("#musteriKayitForm").submit(function(event){
var istek;
// Verileri güvenli bir şekilde savun. Varsayılan gönderimi kontrol et.
event.preventDefault();
// Bekleyen istekleri iptal et.
if (istek) {
istek.abort();
}
// Bazı yerel değişkenleri burada kuruyorum.
var $form = $(this);
// Tüm alanları seçip önbelleğe alıyorum.
var $inputs = $form.find("input, select, button, textarea");
// Verileri formda serileştir
var serializedData = $form.serialize();
// Ajax talebinin süresi için girdileri devre dışı bırakalım.
// Not: form verilerinin serileştirilmesinden sonra öğeleri devre dışı bırakırız.
// Devre dışı form öğeleri serileştirilmeyecektir.
$inputs.prop("disabled", true);
$.ajax({
type: 'post',
url: 'tsettings/islem.php?islem=mKayit',
data: serializedData,
success: function(cevap){ $("#musteriKayitAlertSuccess").html(cevap).hide().fadeIn(700); }
});
// Başarıya çağrılacak geri arama işleyicisi
istek.done(function (response, textStatus, jqXHR){
// Konsola mesaj gönder
console.log("Hooray, it worked!");
});
// Arızada çağrılacak geri arama işleyicisi
istek.fail(function (jqXHR, textStatus, errorThrown){
// Hatası konsola kaydet
console.error(
"The following error occurred: "+
textStatus, errorThrown
);
});
// İstenmeden çağrılacak geri arama işleyicisi
// İstek başarısız oldu veya başarılı olduysa
istek.always(function () {
// Girişleri etkinleştir
$inputs.prop("disabled", false);
});
});
正如Barmar所说,你应该使用event.preventDefault()
这样表单就不会提交给自己, Javascript将能够完成他的工作。
Thanks to everyone who helped me with this problem, thanks to friends who helped solve the problem via stackexchange fixed.感谢所有帮助我解决这个问题的人,感谢通过 stackexchange fix 帮助解决问题的朋友。
If you are experiencing the same problem I leave a code that works for you, and thanks to this code you will be out of trouble :如果您遇到同样的问题,我会留下一个对您有用的代码,多亏了这段代码,您将摆脱困境:
$("#musteriKayitForm").submit(function(event){
var istek;
// Verileri güvenli bir şekilde savun. Varsayılan gönderimi kontrol et.
event.preventDefault();
// Bekleyen istekleri iptal et.
if (istek) {
istek.abort();
}
// Bazı yerel değişkenleri burada kuruyorum.
var $form = $(this);
// Tüm alanları seçip önbelleğe alıyorum.
var $inputs = $form.find("input, select, button, textarea");
// Verileri formda serileştir
var serializedData = $form.serialize();
// Ajax talebinin süresi için girdileri devre dışı bırakalım.
// Not: form verilerinin serileştirilmesinden sonra öğeleri devre dışı bırakırız.
// Devre dışı form öğeleri serileştirilmeyecektir.
$inputs.prop("disabled", true);
$.ajax({
type: 'post',
url: 'tsettings/islem.php?islem=mKayit',
data: serializedData,
success: function(cevap){ $("#musteriKayitAlertSuccess").html(cevap).hide().fadeIn(700); }
});
// Başarıya çağrılacak geri arama işleyicisi
istek.done(function (response, textStatus, jqXHR){
// Konsola mesaj gönder
console.log("Hooray, it worked!");
});
// Arızada çağrılacak geri arama işleyicisi
istek.fail(function (jqXHR, textStatus, errorThrown){
// Hatası konsola kaydet
console.error(
"The following error occurred: "+
textStatus, errorThrown
);
});
// İstenmeden çağrılacak geri arama işleyicisi
// İstek başarısız oldu veya başarılı olduysa
istek.always(function () {
// Girişleri etkinleştir
$inputs.prop("disabled", false);
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.