gpt4 book ai didi

jquery - 使用 Jquery 加载 AJAX 问题

转载 作者:行者123 更新时间:2023-12-01 05:11:06 24 4
gpt4 key购买 nike

我有一个 ajax 调用来加载 xml 中的数据选择。

我没有收到任何 JS 错误,它执行之前的操作,完整的不起作用,我想我没有正确调用数据。

对我在完整的函数循环中做错了什么有什么想法吗?

 $.ajax({
type: "GET",
url: "xml/classes.xml",
dataType: "XML",
beforeSend: function(){
$('#classContainer').append("<p>Loading</p>");},
complete: function() {
$(this).find('monday').each(function(){

var $classdate = $(this);
var title = $classdate.find("class").attr('title');

var level = $classdate.find("class").attr('classLevel');
var time = $classdate.find("time").text();
var duration = $classdate.find("time").attr("duration");
var hourofday = $classdate.find("time").attr("hourofday");
var location = $classdate.find("location").text();



var Monhtml = '<div class="classBlock">';

Monhtml += '<p class="title">' + title + '<span class="loadingPic" alt="Loading" /> ' + ' </p>';
Monhtml += '<p class="infoBar"> <strong>Time:</strong>' + time + '<span class="hour">'+ hourofday +'</span><br>'+'<strong>Duration:</strong>' + duration +'&nbsp;Minutes <br>' + '<strong>Location:</strong>' + location + '<br><strong>Instructor:</strong> </p>';
Monhtml += '<p class="description"> <span class="level">' + level + '</span></p>' ;

Monhtml += '</div>';


$('#classContainer').append($(Monhtml));
});
}
});
});

更改完成为:

 success: function(xml) {
$(xml)

它加载了,有什么区别?

最佳答案

您没有在完整的功能中提供响应。试试这个:

 $.ajax({
type: "GET",
url: "xml/classes.xml",
dataType: "XML",
beforeSend: function(){
$('#classContainer').append("<p>Loading</p>");},
complete: function(resp) {
$(resp).find('monday').each(function(){

var $classdate = $(this);
var title = $classdate.find("class").attr('title');

var level = $classdate.find("class").attr('classLevel');
var time = $classdate.find("time").text();
var duration = $classdate.find("time").attr("duration");
var hourofday = $classdate.find("time").attr("hourofday");
var location = $classdate.find("location").text();



var Monhtml = '<div class="classBlock">';

Monhtml += '<p class="title">' + title + '<span class="loadingPic" alt="Loading" /> ' + ' </p>';
Monhtml += '<p class="infoBar"> <strong>Time:</strong>' + time + '<span class="hour">'+ hourofday +'</span><br>'+'<strong>Duration:</strong>' + duration +' Minutes <br>' + '<strong>Location:</strong>' + location + '<br><strong>Instructor:</strong> </p>';
Monhtml += '<p class="description"> <span class="level">' + level + '</span></p>' ;

Monhtml += '</div>';


$('#classContainer').append($(Monhtml));
});
}
});
});

关于jquery - 使用 Jquery 加载 AJAX 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1284452/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com