我正在尝试从带有序列化功能的表单获取值,并且我正确地发布并保存到数据库但是在此步骤之后我的代码不起作用。有人帮忙吗?
$(document).ready(function() {
$("#kform").submit(function() {
var data = $(this).serialize();
$.ajax({
type: "POST",
url: "yenikayit2.php",
data: data,
dataType: "json",
success: function(data) {
if (data.tip === "dosya") {
alert("tralalala d");
}
if (data.tip === "tercume") {
alert("tralalala t");
}
if (data.tip === "hata") {
alert("tralalala hata");
}
}
});
});

PHP代码
<?php
if($musteri_ekle) { //mysql control function
$musteri_id=mysqli_insert_id($baglanti);
$_SESSION[ 'musteri_id']=$musteri_id;
if ($secilen=="dosya" )
{ echo json_encode(array( "tip"=>"dosya")); }
else if ($secilen == "tercume")
{ echo json_encode(array("tip"=>"tercume")); } }
else { echo json_encode(array("tip"=>"hata")); } ?>
答案 0 :(得分:1)
修改yenikayit2.php以避免PHP致命错误和通知。你可以使用error_reporting(null);
或编辑如下代码
if (isset($musteri_ekle)) { // to avoid undefined variable error
$musteri_id = mysqli_insert_id($baglanti);
$_SESSION['musteri_id'] = $musteri_id;
if ($secilen == "dosya") {
echo json_encode(array("tip" => "dosya"));
} else if ($secilen == "tercume") {
echo json_encode(array("tip" => "tercume"));
}
} else {
echo json_encode(array("tip" => "hata"));
}
答案 1 :(得分:0)
嗯,我意识到我忘了把这些字段放在表格动作上=&#34;&#34;和方法=&#34;&#34;
之后我改变了我的jquery代码:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
$("#kayit").click(function(event) { var data=$("#kform").serialize(); }
&#13;
这可以正常使用