Compilo un form, faccio la submit e tramite jquery ajax chiamo lo script php.
Tale script in caso di errore della query ritorna un json tramite echo json_encode..
Dalla pagina web non riesco in alcun modo a stampare tale errore. Ottengo sempre e comunque
un alert vuoto. Ne sto provando tante ma niente..
Da php:
Da jquery:codice:if($stmt->execute()) { $response["message"] = "Association updated"; header('Content-Type: application/json'); echo json_encode($response); } else { // errore aggiornamento header('Content-Type: application/json'); echo json_encode($pdo->errorInfo()); }
Tra i commenti di "error" ci sono varie alternative che ho provato..codice:$('.create_space_form').on('submit', function () { var address = $('#space').val(); $.ajax({ type:"POST", url:"storeSpace.php", contentType: "application/x-www-form-urlencoded", dataType:"json", data: {address:address}, success: function (data) { }, complete: function () { loadSpaces(); }, error: function (xhr, status, error) { //alert(JSON.stringify(xhr.responseText)); //alert(xhr.responseText); var err = JSON.parse(xhr.responseText); alert(err.message); } });; });

Rispondi quotando
