Javascript Ajax请求错误
我正在自学如何编码,所以这可能是相当笨拙的代码。 这是一个网站,主要是一个与介绍,这是一个简短的视频照片查看器。此视频在播放后隐藏。导航加载各种页面,我正在使用AJAX来完成这项工作。我遇到的问题是AJAX在瞬间加载回视频 最好的方法是你去看网页 这是我的密码。我只包含html和javascript文件,从javascript文件中,您只需要查看前80行左右 当你浏览网站时,你会看到令人讨厌的视频。有人能帮忙吗。谢谢 htmlJavascript Ajax请求错误,javascript,jquery,html,ajax,Javascript,Jquery,Html,Ajax,我正在自学如何编码,所以这可能是相当笨拙的代码。 这是一个网站,主要是一个与介绍,这是一个简短的视频照片查看器。此视频在播放后隐藏。导航加载各种页面,我正在使用AJAX来完成这项工作。我遇到的问题是AJAX在瞬间加载回视频 最好的方法是你去看网页 这是我的密码。我只包含html和javascript文件,从javascript文件中,您只需要查看前80行左右 当你浏览网站时,你会看到令人讨厌的视频。有人能帮忙吗。谢谢 html 马克斯·鲁伊斯|巴拉那 巴拉那 马克斯·鲁伊斯摄影 马克斯·鲁伊
马克斯·鲁伊斯|巴拉那
巴拉那
马克斯·鲁伊斯摄影
马克斯·鲁伊斯·帕兰
佛得角
javascript
var random = Math.floor(Math.random() * 31) + 1;
document.getElementById("front").src = "Images/PARANA/Image" + random + ".jpg";
$( "#content" ).hide();
$( '#header' ).hide();
$( document ).ready(function() {
counter = random;
displayArrows();
updateInfo(counter);
//set up video and text//
var vid = document.getElementById("bgvid");
function stopVideo() {
vid.pause();
$( '#presentacion').delay(3000).hide();
vid.parent().delay(3000).hide();
$( '#allIntro' ).hide();
}
setTimeout(stopVideo, 3000);
function showSite() {
$( '#header' ).delay(1500).fadeIn(2000);
$( "#content" ).delay(1500).fadeIn(2000);
}
showSite();
//once content loaded
$( 'body,html' ).dblclick(function(e){
e.preventDefault();
});
//main page functionality nav//
$( document ).on('click', 'nav a', function(e){
e.preventDefault();
var url = this.href;
$( "nav a.current" ).removeClass("current");
$(this).addClass("current");
$( '#container' ).remove();
$( '#content').load(url + ' #content', function(){
if (url == 'http://maxruiz-parana.com/contact.html'){
$( 'title' ).text('Paraná | Contact');
}
else if (url == 'http://maxruiz-parana.com/gallery.html'){
$( 'title' ).text('Paraná | Gallery');
}
else if (url == 'http://maxruiz-parana.com/about.html'){
$( 'title' ).text('Paraná | About');
$( '#english' ).hide();
}
else if (url == 'http://maxruiz-parana.com/bio.html'){
$( 'title' ).text('Paraná | Bio');
}
else if (url == 'http://maxruiz-parana.com/gallery.html'){
$( 'title' ).text('Max Ruiz | Paraná');
}
counter = random;
$( '#previous' ).css('display', 'none');
}).hide().fadeIn('slow');
});
//main page functionality buttons//
counter = random;
$( document ).on('click', '.buttons', function(e){
if (counter < 1 || counter > 31) {return false;}
e.preventDefault();
var id = e.target.id;
if (id == "next" && counter < 31){counter++;
} else if (id == "previous" && counter > 1){counter--;}
$('#front').fadeOut(500, function() {
getImage(function(){
$('#front').fadeIn(500);
});
});
updateInfo(counter);
});
getImage = function (cb) {
var img = new Image();
img.onload = function () {
document.getElementById("front").src = img.src;
cb();
};
img.src = "Images/PARANA/Image" + counter + ".jpg";
displayArrows();
}
function displayArrows() {
if (counter == 1) {
$( '#previous' ).css('display', 'none');
}
else if (counter > 1 && counter < 31) {
$( '#previous' ).css('display', 'block');
$( '#next' ).css('display', 'block');
}
else if (counter == 31) {
$( '#next' ).css('display', 'none');
}
}
// gallery functionality//
$( document ).on('click', '.littleImages', function(e){
$( '#gall' ).removeClass("current");
$( '#home' ).addClass("current");
var imageSource = $(this).attr('src');
// find the not square picture from the square source
var n = imageSource.lastIndexOf('/');
var result = imageSource.substring(n + 1);
var imageSourceFinal = 'Images/PARANA/' + result;
// find the counter in order to know if it's the last or the first picture and hide corr arrow
counter = imageSource.match(/\d+/g);
$( '#container' ).remove();
$( '#content').load('index.html' + ' #content', function(){
$( '#front' ).attr('src', imageSourceFinal);
if (counter == 1) { $( '#previous' ).css('display', 'none');}
if (counter == 31){ $( '#next' ).css('display', 'none');}
// updateInfo(counter);
testFunction(counter[0]);
}).hide().fadeIn('slow');
});
// legend for pictures functionality
$( document ).on('mouseover', '#front', function(){
$( '#front').fadeTo(300, 0.3);
$( '#info' ).fadeTo(300, 1);
});
$( document ).on('mouseout', '#front', function(){
$( '#front').fadeTo(300, 1);
$( '#info' ).fadeTo(300, 0);
});
function testFunction(number){
switch(number) {
case "1":
$( '#info').text('Verde');
break;
case "2":
$( '#info').text('Pardo');
break;
case "3":
$( '#info').text('Ivinhema');
break;
case "4":
$( '#info').text('Guayquiraró');
break;
case "5":
$( '#info').text('Monday');
break;
case "6":
$( '#info').text('Paranapanema');
break;
case "7":
$( '#info').text('Salado');
break;
case "8":
$( '#info').text('Piquiri');
break;
case "9":
$( '#info').text('Gualeguay');
break;
case "10":
$( '#info').text('Negro');
break;
case "11":
$( '#info').text('Santa Lucía');
break;
case "12":
$( '#info').text('Ivai');
break;
case "13":
$( '#info').text('Corriente');
break;
case "14":
$( '#info').text('Luján');
break;
case "15":
$( '#info').text('Paraguay');
break;
case "16":
$( '#info').text('Iguazú');
break;
case "17":
$( '#info').text('Aguapey');
break;
case "18":
$( '#info').text('Victoria');
break;
case "19":
$( '#info').text('Tieté');
break;
case "20":
$( '#info').text('Pardo');
break;
case "21":
$( '#info').text('Yabeberi');
break;
case "22":
$( '#info').text('Ñacaguazú');
break;
case "23":
$( '#info').text('Tapenagá');
case "24":
$( '#info').text('Arazá');
break;
case "25":
$( '#info').text('Tupicuá');
break;
case "26":
$( '#info').text('Añiá');
break;
case "27":
$( '#info').text('Tamanduatey');
break;
case "28":
$( '#info').text('Aguapey');
break;
}
}
function updateInfo(number) {
switch(number) {
case 1:
$( '#info').text('Verde');
break;
case 2:
$( '#info').text('Pardo');
break;
case 3:
$( '#info').text('Ivinhema');
break;
case 4:
$( '#info').text('Guayquiraró');
break;
case 5:
$( '#info').text('Monday');
break;
case 6:
$( '#info').text('Paranapanema');
break;
case 7:
$( '#info').text('Salado');
break;
case 8:
$( '#info').text('Piquiri');
break;
case 9:
$( '#info').text('Gualeguay');
break;
case 10:
$( '#info').text('Negro');
break;
case 11:
$( '#info').text('Santa Lucía');
break;
case 12:
$( '#info').text('Ivai');
break;
case 13:
$( '#info').text('Corriente');
break;
case 14:
$( '#info').text('Luján');
break;
case 15:
$( '#info').text('Paraguay');
break;
case 16:
$( '#info').text('Iguazú');
break;
case 17:
$( '#info').text('Aguapey');
break;
case 18:
$( '#info').text('Victoria');
break;
case 19:
$( '#info').text('Tieté');
break;
case 20:
$( '#info').text('Pardo');
break;
case 21:
$( '#info').text('Yabeberi');
break;
case 22:
$( '#info').text('Ñacaguazú');
break;
case 23:
$( '#info').text('Tapenagá');
case 24:
$( '#info').text('Arazá');
break;
case 25:
$( '#info').text('Tupicuá');
break;
case 26:
$( '#info').text('Añiá');
break;
case 27:
$( '#info').text('Tamanduatey');
break;
case 28:
$( '#info').text('Aguapey');
break;
}
}
// About functionality
$( document ).on('click', '#enButton', function(){
$( '#english' ).fadeIn();
$( '#french' ).fadeOut();
});
$( document ).on('click', '#frButton', function(){
$( '#english' ).fadeOut();
$( '#french' ).fadeIn();
});
});
var random=Math.floor(Math.random()*31)+1;
document.getElementById(“front”).src=“Images/PARANA/Image”+random+”.jpg”;
$(“#内容”).hide();
$('#header').hide();
$(文档).ready(函数(){
计数器=随机;
显示箭头();
更新信息(计数器);
//设置视频和文本//
var vid=document.getElementById(“bgvid”);
函数stopVideo(){
参阅暂停();
$('#presentacion').delay(3000.hide();
vid.parent().delay(3000.hide();
$('allIntro').hide();
}
设置超时(停止视频,3000);
函数showSite(){
美元("标题").延迟(1500年).法代因(2000年),;
$(“#内容”)。延迟(1500)。法代因(2000);
}
showSite();
//一旦内容加载
$('body,html').dblclick(函数(e){
e、 预防默认值();
});
//主页功能导航//
$(文件)。在('点击','导航a',功能(e){
e、 预防默认值();
var url=this.href;
$(“当前资产净值”).removeClass(“当前”);
$(此).addClass(“当前”);
$(“#容器”).remove();
$('#content').load(url+'#content',function(){
如果(url=='http://maxruiz-parana.com/contact.html'){
$('title')。文本('Paraná| Contact');
}
else if(url=='http://maxruiz-parana.com/gallery.html'){
$('title')。文本('Paraná| Gallery');
}
else if(url=='http://maxruiz-parana.com/about.html'){
$('title')。文本('ParanáAbout');
$(“#英语”).hide();
}
else if(url=='http://maxruiz-parana.com/bio.html'){
$('title')。文本('Paraná| Bio');
}
else if(url=='http://maxruiz-parana.com/gallery.html'){
$('title')。文本('Max Ruiz | Paraná');
}
计数器=随机;
$('#previous').css('display','none');
}).hide().fadeIn('slow');
});
//主页功能按钮//
计数器=随机;
$(文档).on('单击','按钮'),函数(e){
如果(计数器<1 | |计数器>31){返回false;}
e、 预防默认值();
var id=e.target.id;
如果(id==“next”&&counter<31){counter++;
}如果(id==“previous”&&counter>1){counter--;}
$('#front').fadeOut(500,function(){
getImage(函数(){
美元("前").法代因(500),;
});
});
更新信息(计数器);
});
getImage=函数(cb){
var img=新图像();
img.onload=函数(){
document.getElementById(“front”).src=img.src;
cb();
};
img.src=“Images/PARANA/Image”+counter+“.jpg”;
显示箭头();
}
函数displayArrows(){
如果(计数器==1){
$('#previous').css('display','none');
}
否则如果(计数器>1&&计数器<31){
$('#previous').css('display','block');
$('#next').css('display','block');
}
否则如果(计数器==31){
$('#next').css('display','none');
}
}
//图库功能//
$(文档).on('click','littleImages',函数(e){
$('#gall').removeClass(“当前”);
$('#home').addClass(“当前”);
var imageSource=$(this.attr('src');
//从方形源中查找非方形图片
var n=imageSource.lastIndexOf('/');
var result=imageSource.substring(n+1);
var imageSourceFinal='Images/PARANA/'+结果;
//找到计数器以了解它是最后一张还是第一张图片,然后隐藏箭头
计数器=imageSource.match(/\d+/g);
$(“#容器”).remove();
$('#content').load('index.html'+'#content',function(){
$('#front').attr('src',imageSourceFinal);
if(counter==1){$('#previous').css('display','none');}
if(counter==31){$('#next').css('display','none');}
//更新信息(计数器);
testFunction(计数器[0]);
}).hide().fadeIn('slow');
});
//图片功能图例
$(文档).on('mouseover','#front',function(){
美元("前").法德托(300,0.3),;
$('信息').fadeTo(300,1);
});
$(文档).on('mouseout','#front',function(){
元("前").法德托(300,1),;
$(#info').fadeTo(300,0);
});
函数测试函数(编号){
开关(编号){
案例“1”:
$('#info')。文本('Verde');
打破
案例“2”:
$('info')。文本('Pardo');
打破
案例“3”:
$('#info').text('Ivinhema');
打破
案例“4”:
$(“#info”).text('guayquirró');
打破
案例“5”:
var random = Math.floor(Math.random() * 31) + 1;
document.getElementById("front").src = "Images/PARANA/Image" + random + ".jpg";
$( "#content" ).hide();
$( '#header' ).hide();
$( document ).ready(function() {
counter = random;
displayArrows();
updateInfo(counter);
//set up video and text//
var vid = document.getElementById("bgvid");
function stopVideo() {
vid.pause();
$( '#presentacion').delay(3000).hide();
vid.parent().delay(3000).hide();
$( '#allIntro' ).hide();
}
setTimeout(stopVideo, 3000);
function showSite() {
$( '#header' ).delay(1500).fadeIn(2000);
$( "#content" ).delay(1500).fadeIn(2000);
}
showSite();
//once content loaded
$( 'body,html' ).dblclick(function(e){
e.preventDefault();
});
//main page functionality nav//
$( document ).on('click', 'nav a', function(e){
e.preventDefault();
var url = this.href;
$( "nav a.current" ).removeClass("current");
$(this).addClass("current");
$( '#container' ).remove();
$( '#content').load(url + ' #content', function(){
if (url == 'http://maxruiz-parana.com/contact.html'){
$( 'title' ).text('Paraná | Contact');
}
else if (url == 'http://maxruiz-parana.com/gallery.html'){
$( 'title' ).text('Paraná | Gallery');
}
else if (url == 'http://maxruiz-parana.com/about.html'){
$( 'title' ).text('Paraná | About');
$( '#english' ).hide();
}
else if (url == 'http://maxruiz-parana.com/bio.html'){
$( 'title' ).text('Paraná | Bio');
}
else if (url == 'http://maxruiz-parana.com/gallery.html'){
$( 'title' ).text('Max Ruiz | Paraná');
}
counter = random;
$( '#previous' ).css('display', 'none');
}).hide().fadeIn('slow');
});
//main page functionality buttons//
counter = random;
$( document ).on('click', '.buttons', function(e){
if (counter < 1 || counter > 31) {return false;}
e.preventDefault();
var id = e.target.id;
if (id == "next" && counter < 31){counter++;
} else if (id == "previous" && counter > 1){counter--;}
$('#front').fadeOut(500, function() {
getImage(function(){
$('#front').fadeIn(500);
});
});
updateInfo(counter);
});
getImage = function (cb) {
var img = new Image();
img.onload = function () {
document.getElementById("front").src = img.src;
cb();
};
img.src = "Images/PARANA/Image" + counter + ".jpg";
displayArrows();
}
function displayArrows() {
if (counter == 1) {
$( '#previous' ).css('display', 'none');
}
else if (counter > 1 && counter < 31) {
$( '#previous' ).css('display', 'block');
$( '#next' ).css('display', 'block');
}
else if (counter == 31) {
$( '#next' ).css('display', 'none');
}
}
// gallery functionality//
$( document ).on('click', '.littleImages', function(e){
$( '#gall' ).removeClass("current");
$( '#home' ).addClass("current");
var imageSource = $(this).attr('src');
// find the not square picture from the square source
var n = imageSource.lastIndexOf('/');
var result = imageSource.substring(n + 1);
var imageSourceFinal = 'Images/PARANA/' + result;
// find the counter in order to know if it's the last or the first picture and hide corr arrow
counter = imageSource.match(/\d+/g);
$( '#container' ).remove();
$( '#content').load('index.html' + ' #content', function(){
$( '#front' ).attr('src', imageSourceFinal);
if (counter == 1) { $( '#previous' ).css('display', 'none');}
if (counter == 31){ $( '#next' ).css('display', 'none');}
// updateInfo(counter);
testFunction(counter[0]);
}).hide().fadeIn('slow');
});
// legend for pictures functionality
$( document ).on('mouseover', '#front', function(){
$( '#front').fadeTo(300, 0.3);
$( '#info' ).fadeTo(300, 1);
});
$( document ).on('mouseout', '#front', function(){
$( '#front').fadeTo(300, 1);
$( '#info' ).fadeTo(300, 0);
});
function testFunction(number){
switch(number) {
case "1":
$( '#info').text('Verde');
break;
case "2":
$( '#info').text('Pardo');
break;
case "3":
$( '#info').text('Ivinhema');
break;
case "4":
$( '#info').text('Guayquiraró');
break;
case "5":
$( '#info').text('Monday');
break;
case "6":
$( '#info').text('Paranapanema');
break;
case "7":
$( '#info').text('Salado');
break;
case "8":
$( '#info').text('Piquiri');
break;
case "9":
$( '#info').text('Gualeguay');
break;
case "10":
$( '#info').text('Negro');
break;
case "11":
$( '#info').text('Santa Lucía');
break;
case "12":
$( '#info').text('Ivai');
break;
case "13":
$( '#info').text('Corriente');
break;
case "14":
$( '#info').text('Luján');
break;
case "15":
$( '#info').text('Paraguay');
break;
case "16":
$( '#info').text('Iguazú');
break;
case "17":
$( '#info').text('Aguapey');
break;
case "18":
$( '#info').text('Victoria');
break;
case "19":
$( '#info').text('Tieté');
break;
case "20":
$( '#info').text('Pardo');
break;
case "21":
$( '#info').text('Yabeberi');
break;
case "22":
$( '#info').text('Ñacaguazú');
break;
case "23":
$( '#info').text('Tapenagá');
case "24":
$( '#info').text('Arazá');
break;
case "25":
$( '#info').text('Tupicuá');
break;
case "26":
$( '#info').text('Añiá');
break;
case "27":
$( '#info').text('Tamanduatey');
break;
case "28":
$( '#info').text('Aguapey');
break;
}
}
function updateInfo(number) {
switch(number) {
case 1:
$( '#info').text('Verde');
break;
case 2:
$( '#info').text('Pardo');
break;
case 3:
$( '#info').text('Ivinhema');
break;
case 4:
$( '#info').text('Guayquiraró');
break;
case 5:
$( '#info').text('Monday');
break;
case 6:
$( '#info').text('Paranapanema');
break;
case 7:
$( '#info').text('Salado');
break;
case 8:
$( '#info').text('Piquiri');
break;
case 9:
$( '#info').text('Gualeguay');
break;
case 10:
$( '#info').text('Negro');
break;
case 11:
$( '#info').text('Santa Lucía');
break;
case 12:
$( '#info').text('Ivai');
break;
case 13:
$( '#info').text('Corriente');
break;
case 14:
$( '#info').text('Luján');
break;
case 15:
$( '#info').text('Paraguay');
break;
case 16:
$( '#info').text('Iguazú');
break;
case 17:
$( '#info').text('Aguapey');
break;
case 18:
$( '#info').text('Victoria');
break;
case 19:
$( '#info').text('Tieté');
break;
case 20:
$( '#info').text('Pardo');
break;
case 21:
$( '#info').text('Yabeberi');
break;
case 22:
$( '#info').text('Ñacaguazú');
break;
case 23:
$( '#info').text('Tapenagá');
case 24:
$( '#info').text('Arazá');
break;
case 25:
$( '#info').text('Tupicuá');
break;
case 26:
$( '#info').text('Añiá');
break;
case 27:
$( '#info').text('Tamanduatey');
break;
case 28:
$( '#info').text('Aguapey');
break;
}
}
// About functionality
$( document ).on('click', '#enButton', function(){
$( '#english' ).fadeIn();
$( '#french' ).fadeOut();
});
$( document ).on('click', '#frButton', function(){
$( '#english' ).fadeOut();
$( '#french' ).fadeIn();
});
});
vid.parent().delay(3000).hide()
setTimeout( function(){
$("#bgvid").parent().hide()
}, 3000);