Reputation: 25
Working on a small project where I want to implement a jquery slider to hold testimonials on the website's support page. To make life easier I want the testimonials to be contained in an XML document. The slider works fine on the page but when I try to use a function to get the testimonial text from the XML document, it works as well as a North Korean rocket.
Scripts in :
<head>
<title>Crutchfield Customer Support - Online Support Center</title>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="support.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" type="text/javascript"></script>
<script src="slider/jquery.bxSlider.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#slider1').bxSlider({
auto: true,
autoControls: false,
nextText: '',
prevText: ''
});
});
</script>
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
type: "GET",
url: "testimonials.xml",
dataType: "xml",
success: function(xml) {
var select = $('#slider1');
$(xml).find('testimonials').each(function(){
var text = $(this).find('text').text();
select.append("<li class='test'>"+text+"</li>");
});
}
});
});
</script>
</head>
HTML for the slider:
<div id="testimonials">
<div class="testimonialGroupOne">
<ul id="slider1">
<li>loading</li>
</ul>
</div>
</div>
I may add another slider but probably not, could the problem be with the divitis?
So basically the ordered list doesn't populate, here's the xml file so far:
<?xml version="1.0" encoding="ISO-8859-1"?>
<testimonials>
<text>"I have been doing business with Crutchfield for over fifteen years and have yet to have a negative experience. Their customer service is second to none."</text>
<text>"I've been a Crutchfield customer for over 20 years. I've found their customer service and technical support to surpass every other vendor in this business. Without exception, every contact I've had with Crutchfield employees, I have found them to be professional, competent, respectful and patient."</text>
</testimonials>
Upvotes: 0
Views: 1149
Reputation: 11
try this
var mySlider;
$(document).ready(function () {
$.ajax({
type: "GET",
url: "data/yourxml.xml",
dataType: "xml",
success: function (xml) {
$(xml).find('testimonials').each(function(){
xml_name = $(this).find('name').text();
$('#slide').append('<li>' + xml_name + '</li>')
});
$(function () {
mySlider = $('#slide').bxSlider({
auto: true,
controls: false
});
mySlider.reloadShow();
})
}
});
});
Upvotes: 1