Javascript HTML AJAX方法不起作用
我想要HTML上的一个按钮,通过使用AJAX更改某些页面的内容非常简单的代码,但当我尝试更改它时,它会说:Javascript HTML AJAX方法不起作用,javascript,html,ajax,Javascript,Html,Ajax,我想要HTML上的一个按钮,通过使用AJAX更改某些页面的内容非常简单的代码,但当我尝试更改它时,它会说: " video.js:20 Failed to load file:///C:/xampp/htdocs/Rain%20Oficial/texto_prueba.txt: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https."
" video.js:20 Failed to load file:///C:/xampp/htdocs/Rain%20Oficial/texto_prueba.txt: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https."
我是通过一个教程来做的,它创建了at.txt文件,并使页面显示了.txt文件中的内容,但我试图用HTML youtube工具链接yotube视频的HTML标记替换.txt文件,但即使是教程示例也不适用于此处的视频:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="css/Inicio.css">
<link rel="stylesheet" href="css/fonts.css">
<link rel="icon" href="">
<title>Rain | Inicio</title>
</head>
<body>
<header class="main">
<!--a class="logo-header" href="https://cdn.pixabay.com/photo/2016/10/16/16/32/drop-of-water-1745699_960_720.png"-->
<span class="site-name"><h1><a href="Inicio.html">rain</a></h1></span>
<span class="site-desc">Pocos Botones, Dias Memorables</span>
</a>
</header>
<div class="Prin">
<center><h1 class="titulo">¿Qué es Rain?</h1></center>
<p class="descrip">Mientras que para acceder a las demás redes sociales o foros, estos requieren ingresar datos personales y completar formularios tediosos, <font color="#5769b4"><b>Rain</b></font> ofrece a sus Usuarios un sistema de foro simplificado y seguro para sus usuarios, no tengan problemas con la privacidad, ni tengan que acostumbrarse a una interfaz complicada, de esta manera es como en nuestra Página Web cumplimos con nuestro lema: <br><br><font color="#365886"><b>Pocos botones,</b></font> <b><font color="#835ebe">Días memorables.</font></b></p>
<button id="cargar" value="cargar">¿Interesado/a en nuestro video promocional?</button>
</div>
<!--Div que funciona cuando el usuario interactue por medio de AJAX-->
<div class="Prin-video">
</div>
<ul class="butt">
<li><span class="icon-droplet"></span><a href="Formulario.html">Inicia Sesión</a></li>
<li><span class="icon-profile"></span><a href="Registrarse.html">Registrarse</a></li>
</ul>
<ul class="butt-res">
<li><span class="icon-droplet"></span><a href="Formulario.html">Inicia Sesión</a></li>
<li><span class="icon-profile"></span><a href="Registrarse.html">Registrarse</a></li>
</ul>
<script src="js/video.js"></script>
</body>
</html>
'/*jslint devel: true */
var btnCargar = document.getElementById('cargar');
function cargarContenidoAjax() {
'use strict';
var xhr = new XMLHttpRequest();
xhr.open("GET", "texto_prueba.txt", true);
xhr.onreadystatechange = function () {
console.log(xhr.readyState);
if (xhr.readyState === 4 && xhr.status === 200) {
var contenido = document.getElementById('Prin');
contenido.innerHTML = xhr.responseText;
}
};
xhr.send();
}
btnCargar.addEventListener('click', cargarContenidoAjax);'
雨|伊尼西奥
Pocos Botones,Dias纪念品
什么雨?
作为一个参与者,我们需要一个完整的个人数据和公式化的数据,一个简单化的使用系统和一个使用系统,没有特权的问题,我需要一个共同的干涉,如果你能在网上找到一个新的网站,你就可以把它作为记忆
有兴趣看一个新的视频宣传片吗?
'/*jslint-devel:true*/
var btnCargar=document.getElementById('cargar');
函数cargarContenidoAjax(){
"严格使用",;
var xhr=new XMLHttpRequest();
打开(“GET”,“texto_prueba.txt”,true);
xhr.onreadystatechange=函数(){
console.log(xhr.readyState);
如果(xhr.readyState==4&&xhr.status==200){
var contenido=document.getElementById('Prin');
contenido.innerHTML=xhr.responseText;
}
};
xhr.send();
}
btnCargar.addEventListener('click',cargarContenidoAjax);'
对代码做一些小的更改,如
xhr.open("GET", "http://localhost/Rain Oficial/texto_prueba.txt", true);
而且它会很好地工作你有javascript。。。这不是在脚本标记中,或者javascript在一个单独的文件中?我觉得有义务指出
center
标记的使用,它甚至在HTML4中也被弃用,但在这里与HTML5标记一起使用,在span
中使用块级标记。此HTML确实无效。xhr.open(“GET”,“texto\u prueba.txt”
…文件texto\u prueba.txt
与您发布的包含HTML的文件位于同一文件夹中吗?您使用的是web服务器还是这只是在浏览器中打开的文件?可能是哪个浏览器?Chrome?我不是在询问HTML语法…”它无效“它只是工作…是的,它在同一个文件夹中。