El código de solicitud GET para AJAX en JavaScript/JS es el siguiente:
<script type = "text/javaScript">/* create xmlhttprequest object*/var xmlhttp; función getxmlhttpObject () {if (window.xmlhttprequest) {// código para IE7+, Firefox, Chrome, Opera, Safari XMLHTTP = nuevo xmlhttprequest (); } else {// código para IE6, IE5 xmlhttp = new ActiveXObject ("Microsoft.xmlhttp"); } return xmlhttp; } // ----------------------- // function getLabelSget () {xmlhttp = getxmlhttpobject (); if (xmlhttp == null) {alert ('su navegador no admite AJAX!'); devolver; } var id = document.getElementById ('id'). valor; var url = "http://www.leefrom.com?id="+id+"& t/"+math.random (); xmlhttp.open ("get", url, verdadero); xmlhttp.onreadyStateChange = favork; // Después de enviar el evento, se recibió el mensaje. La función de llamada xmlhttp.send (); } function getokget () {if (xmlhttp.readyState == 1 || xmlhttp.readyState == 2 || xmlhttp.readyState == 3) {// Local Semunt: Carging} if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {var d = xmlhttp.esponsetext; // El procesamiento devuelve el resultado}} </script>Solicitud de publicación para AJAX para JavaScript/JS:
<script type = "text/javaScript">/* create xmlhttprequest object*/var xmlhttp; función getxmlhttpObject () {if (window.xmlhttprequest) {// código para IE7+, Firefox, Chrome, Opera, Safari XMLHTTP = nuevo xmlhttprequest (); } else {// código para IE6, IE5 xmlhttp = new ActiveXObject ("Microsoft.xmlhttp"); } return xmlhttp; } // ----------------------- // function getLabelsPost () {xmlhttp = getxmlhttpobject (); if (xmlhttp == null) {alert ('su navegador no admite AJAX!'); devolver; } var url = "http://www.lifefrom.com/t/"+math.random (); xmlhttp.open ("post", url, verdadero); xmlhttp.setRequestHeader ("Content-type", "Application/x-www-form-urlencoded"); xmlhttp.send (); xmlhttp.onreadyStateChange = getLabelSok; // Después de enviar el evento, se recibió el mensaje, llamando a la función} function getokPost () {if (xmlhttp.readystate == 1 || xmlhttp.readyState == 2 || xmlhttp.readystate == 3) {// rápido: aviso de carga/aviso/procesamiento/procesamiento/procesamiento/procesamiento/procesamiento/procesamiento}} (xmlhttp.readyState == 4 && xmlhttp.status == 200) {var d = xmlhttp.Responsetext; // Valor de retorno // Valor de retorno de procesamiento}} </script>Nota: XMLHTTPREQUEST es la base de AJAX. Al crear objetos xmlhttprequest, debe estar en la misma etiqueta '<script> </script>' como el método AJAX que escribió. De lo contrario, la solicitud AJAX se equivocará y los datos no se devolverán. JavaScript/JS AJAX POST/GET Solicitud.
Lo anterior es el conocimiento relevante de JS AJAX nativo, Get and Post Solicitar el código de instancia que se le presenta. Espero que te sea útil. Si tiene alguna pregunta, déjame un mensaje y el editor le responderá a tiempo. ¡Muchas gracias por su apoyo al sitio web de Wulin.com!