Estoy estudiando un código y necesito ayuda para aprender más.
El siguiente código JS proviene de un formulario html de preguntas y respuestas que envía datos al servidor. Comprueba la respuesta y en el servidor y califica al usuario.
Necesito ayuda para escribir un código PHP que reciba las entradas usando el método GET y repita "ok" en el html.
JS:
var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if(this.readyState == 4 && this.status == 200) { if(this.responseText == "ok") { document.getElementById("messagefont").innerHTML = checkans; document.getElementById("answer").value = ""; document.getElementById('submit-btn').value = continuebutton; checkans.focus();PHP:
<?php header('Content-Type: application/json'); $errors = array (); if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ); if (isset ($_GET['answer'])) { $answer = $_GET["answer"]; } else { array_push ($errors, no); } $response = ""; if (sizeof ($errors) > 0) { $response = implode (",", $errors); } else { $response = ok; } echo json_encode($response); ?>Parece que no estoy haciendo algo bien con PHP, por favor necesito ayuda/guía para arreglar el código PHP correctamente.