{"id":273,"date":"2023-02-09T18:44:13","date_gmt":"2023-02-09T18:44:13","guid":{"rendered":"http:\/\/javigomez.org\/?p=273"},"modified":"2025-09-29T20:34:09","modified_gmt":"2025-09-29T20:34:09","slug":"llamada-ajax-recibiendo-un-texto","status":"publish","type":"post","link":"https:\/\/javigomez.org\/index.php\/2023\/02\/09\/llamada-ajax-recibiendo-un-texto\/","title":{"rendered":"AJAX: Llamada recibiendo un texto"},"content":{"rendered":"\n<p>En el siguiente c\u00f3digo se realiza una llamada ajax desde javaScript hacia un texto plano que est\u00e1 en el servidor.<\/p>\n\n\n\n<p>El archivo aj1.ax que est\u00e1 en el servidor tiene el siguiente contenido:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Archivo de ejemplo en el servidor. XXXXXXX<\/code><\/pre>\n\n\n\n<p>El archivo fuente es el siguiente:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html>\n&lt;html>\n&lt;head>\n&lt;title>AJAX&lt;\/title>\n&lt;meta http-equiv=\"content-type\" content=\"text\/html; charset=UTF-8\">\n&lt;meta http-equiv=\"X-UA-Compatible\"content=\"IE=edge\" \/>\n&lt;\/head>\n&lt;body>\n&lt;script>\n\nfunction test(file) {\n    var archivo = new XMLHttpRequest();\n    \n    archivo.open(\"GET\", file, false);\n    console.log(\"1\");\n    archivo.onreadystatechange = function () {\n        console.log(\"2\");\n        if (archivo.readyState == 4) {\n            console.log(\"3\");\n            if (archivo.status == 200 || archivo.status == 0) {\n                console.log(\"4\");\n                var Texto = archivo.responseText;\n                alert(\"Contenido: \\n\" + Texto);\n            }\n        }\n    }\n    console.log(\"5\");\n    archivo.send(null);\n}\n&lt;\/script>\n&lt;input type=\"button\" value=\"Ajax http\" onClick=\"test('http:\/\/localhost\/X\/aj1.ax?xxx')\">\n&lt;\/body>\n&lt;\/html><\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>En el siguiente c\u00f3digo se realiza una llamada ajax desde javaScript hacia un texto plano que est\u00e1 en el servidor. El archivo aj1.ax que est\u00e1 &hellip; <\/p>\n","protected":false},"author":1,"featured_media":274,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[21,204],"class_list":["post-273","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-ajax","tag-javascript"],"_links":{"self":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/273","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/comments?post=273"}],"version-history":[{"count":1,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/273\/revisions"}],"predecessor-version":[{"id":951,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/273\/revisions\/951"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/media\/274"}],"wp:attachment":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/media?parent=273"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/categories?post=273"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/tags?post=273"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}