• 22-11-2022, 21:00:46
    #1
    Merhabalar.
    İndex.php'mde başka sayfadan veri çeken bir ajax kodum var.
    <script src=https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js></script>
    <script>
        $(document).ready(function()
        {
            $("#veriGonder").click(function (){
                var kilo = $("input[name=kilo]").val();
                $.ajax({
                    url: "hesapla.php?mode=insert",
                    type: "POST",
                    data: {
                        'kilo':kilo
                    },
                    success: function(result)
                    {
                        $(".alert").show();
                        $(".alert").html(result);
                    }});
            });
        })
    </script>
    Bu kod hesapla .php ye gerekli verileri yollayıp orada echolanan tüm herşeyi alert klasslı divin içinde gösteriyor.
    Fakat benim istediğim bu gelen verileri ayrı ayrı olarak index.php de yazdırmak.
    Örneğin hesapla .php 'de şu iki işlem olsun
    $islem1 = 1 + 1;
    $islem2 = 2 + 2;
    bu iki işlemi nasıl index.php ye,
    <div class="alert">
    <?php echo $islem1; ?>
    </div>
    <div class="alert">
    <?php echo $islem2; ?>
    </div>
    şeklinde yazdırabilirim.?

    Hesapla.php
    <?php
    switch ($_GET['mode']) {
        case 'insert':
            if ($_POST) {
               
                // işlemler buraya
            }
            break;
    }
  • 22-11-2022, 21:10:06
    #2
    🌐 𝘀𝗼𝗰𝗶𝗳𝗹𝘆.𝗰𝗼𝗺
    Divlere farklı ID ver hocam.

    <div id="alert1" class="alert"></div>
    <div id="alert2" class="alert"></div>

    gibi.

    success: fonksiyonunu bu şekilde değiştir.

    function(result){
    $("#alert1").show();
    $("#alert2").show();
    $("#alert1").html(result);
    $("#alert2").html(result);
    }

    Ama gelen result verisini yine parse etmen lazım.
  • 22-11-2022, 21:18:13
    #3
    Js tarafı
    <script src=https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js></script>
    <script>
    $(document).ready(function() {
    $("#veriGonder").click(function (){
    var kilo = $("input[name=kilo]").val();
    $.ajax({
    url: "hesapla.php?mode=insert",
    type: "POST",
    data: {'kilo':kilo},
    dataType: "json",
    success: function(result) {
    $(".alert").show();
    $("#birinci").html(result["islem1"]);
    $("#ikinci").html(result["islem2"]);
    }
    });
    });
    })
    </script>

    Php tarafı
    <?php
    switch ($_GET['mode']) {
    case 'insert':
    if ($_POST) {
    
    $data["islem1"] = 1 + 1;
    $data["islem2"] = 2 + 2;
    
    echo json_encode($data);
    
    }
    break;
    }
  • 22-11-2022, 21:41:46
    #4
    omergunay adlı üyeden alıntı: mesajı görüntüle
    Js tarafı
    <script src=https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js></script>
    <script>
    $(document).ready(function() {
    $("#veriGonder").click(function (){
    var kilo = $("input[name=kilo]").val();
    $.ajax({
    url: "hesapla.php?mode=insert",
    type: "POST",
    data: {'kilo':kilo},
    dataType: "json",
    success: function(result) {
    $(".alert").show();
    $("#birinci").html(result["islem1"]);
    $("#ikinci").html(result["islem2"]);
    }
    });
    });
    })
    </script>

    Php tarafı
    <?php
    switch ($_GET['mode']) {
    case 'insert':
    if ($_POST) {
    
    $data["islem1"] = 1 + 1;
    $data["islem2"] = 2 + 2;
    
    echo json_encode($data);
    
    }
    break;
    }
    Çok teşekkür ederim! İşe Yaradı!
  • 22-11-2022, 21:42:22
    #5
    tolgasen adlı üyeden alıntı: mesajı görüntüle
    Divlere farklı ID ver hocam.

    <div id="alert1" class="alert"></div>
    <div id="alert2" class="alert"></div>

    gibi.

    success: fonksiyonunu bu şekilde değiştir.

    function(result){
    $("#alert1").show();
    $("#alert2").show();
    $("#alert1").html(result);
    $("#alert2").html(result);
    }

    Ama gelen result verisini yine parse etmen lazım.
    Yardımın için çok teşekkür ederim!