Visualizzazione dei risultati da 1 a 3 su 3

Visualizzazione discussione

  1. #1

    Undefined array key 'val' - chiamata ajax

    Ciao a tutti
    Devo effettuare una richiesta ajax con fetch inviando un valore questo è quello che ho fatto:

    codice:
    async function http(data) {
            const objdt = {
                val: data
            }
            const response = await fetch("lib/bot.php", {
                method: "POST",
                hedaers: {"Content-type": "application/x-www-form-urlencoded; charset=UTF-8"},
                body: JSON.stringify({objdt})
            })
            .then(response => response.text())
                .then(data => inschat(data))
            .catch(err => console.log(err));
    }
    
    var inschat = (dt) => {
            alert(dt.data);
    }
    
    const inpChat = document.querySelector("input[name=chat_input_text]");
    inpChat.addEventListener("keypress", (event) => {
            if(event.keyCode === 13 && inpChat.value !== ""){
                let data = inpChat.value;
                http(data);
            }
    });
    E questo è un semplice codice in php giusto per vedere se passano i valori:
    Codice PHP:
    $dt trim($_POST["val"]);
    echo 
    $dt 
    Il problema e che mi da errore warning Undefined array key 'val'
    Un consiglio grazie sono davvero bloccato in questo punto
    Ultima modifica di ciro78; 15-04-2022 a 22:07

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.