我无法从json编码获得响应 - php

我正在尝试使用序列化功能从表单获取值,并且正确地将其发布并保存到数据库,但是在此步骤之后我的代码无法正常工作。有人帮忙吗?

 $(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")); } ?>

参考方案

修改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"));
}

PHP-MySQL结果转换为JSON - php

我试图了解如何将MySQL结果转换为JSON格式,以便以后可以在Javascript中使用此JSON来构建HTML表。但是我的代码只是产生大量的空值,我还不明白为什么。$result = mysqli_query($con, "SELECT * FROM Customers"); $test = json_encode($result);…

json_encode网址失败 - php

有人在this bug附近吗?echo json_encode(array('url'=>'/foo/bar')); {"url":"\/foo\/bar"} 我使用Zend_Json and Zend_Json_Expr以便我甚至可以在js对象中获取回调函数-但我无法获得…

json_encode的特定方式 - php

所以这是我的PHP<?php include 'connect.php'; $sql = "SELECT name from startup_schema"; $result = mysqli_query($mysqli, $sql) or die("Error in Selecting " …

jQuery Ajax加载仅适用于单个单词变量 - php

在我的PHP文件中,我将一些变量从输入框传递到链接中,该链接通过jQuery的ajax load函数在其URL中使用该变量加载页面。整个系统运行良好,但仅适用于单字变量。每当涉及到空格时,我的Ajax通话都会中断。我假设这是一个编码问题,但是我也有一些疑问。基本上,它归结为我的PHP文件中的这一行代码,这导致了混乱。是否有可能找出格式是否正确,或者为什么在多…

jQuery帮助获取JSON数据 - php

我在这里遇到麻烦,我的json数据输出如下:{"date":[{"day_w":"Tuesday","day_n":"28","month":"Dec"}],"subscriptions":[{�…