I am trying to implement a slider in a coldfusion page & written jQuery script for fetching images through XML file. My XML file is including paths & other details of the Image. But it’s not working, though it did for simple file on my WAMP server.
ColdFusion Code:
<cfoutput>
<script type="text/javascript" src="#request.serverCustom#rangers/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="#request.serverCustom#rangers/js/simplegallery.js"></script>
<script type="text/javascript">
var myArray = [];
$(document).ready(function() {
alert("outside");
$.ajax({
//alert("ajax inside");
type: "GET",
url: "#request.serverCustom#rangers/js/sites.xml",
dataType: "xml",
success: function(xml) {
var count = 0;
$(xml).find('site').each(function() {
var url = $(this).find('url').text();
var target = $(this).find('target').text();
var imageURL = $(this).find('imageURL').text();
var alt = $(this).find('alt').text();
myArray[parseInt(count)] = new Array(imageURL, url, target, alt);
count++;
});
var mygallery2 = new simpleGallery({
wrapperid: "simplegallery2",
dimensions: [400, 240],
imagearray: myArray,
autoplay: [true, 10000, 99],
persist: true,
fadeduration: 1000,
oninit: function() {
},
onslide: function(curslide, i) {
}
})
}
});
alert(mygallery2);
});
</script>
<div style="background: black none repeat scroll 0% 0%; overflow: hidden;
position: relative; visibility: visible; -moz-background-clip: border; -moz-background-origin:
padding; -moz-background-inline-policy: continuous; width: 400px; height: 265px;" id="simplegallery2">
</div>
</cfoutput>
My XML Code:-
<?xml version="1.0" encoding="iso-8859-1"?>
<sites>
<site>
<url><![CDATA[http://facebook.com]]></url>
<target>_new</target>
<alt>First Image : Random Image with Baloon(Will Go to FB)</alt>
<imageURL><![CDATA[/img/Image1.jpg]]></imageURL>
</site>
<site>
<url><![CDATA[http://google.com]]></url>
<target>_new</target>
<alt>Second Image : Random Image of a Toy(Will Go to Google)</alt>
<imageURL><![CDATA[/img/Image2.jpg]]></imageURL>
</site>
<site>
<url><![CDATA[http://twitter.com]]></url>
<target>_new</target>
<alt>Third Image : Random Image with Lighter with Water Filled</alt>
<imageURL><![CDATA[/img/Image3.jpg]]></imageURL>
</site>
<site>
<url><![CDATA[http://enablingdimensions.com]]></url>
<target>_new</target>
<alt>Fourth Image : A Image from Game(Will Go To Our Site)</alt>
<imageURL><![CDATA[/img/Image4.jpg]]></imageURL>
</site>
<site>
<url><![CDATA[http://ed.konnected.me]]></url>
<target>_new</target>
<alt>Fifth Image : A Cartoon in Yellow Background</alt>
<imageURL><![CDATA[/img/Image5.jpg]]></imageURL>
</site>
<site>
<url><![CDATA[http://yahoo.com]]></url>
<target>_new</target>
<alt>Sixth Image : Eating Fish with Anger(Will Go To Yahoo)</alt>
<imageURL><![CDATA[/img/Image6.jpg]]></imageURL>
</site>
</sites>
My folder “img” is located in the local path. Even I tried alert inside $.ajax, but it got break. I tried with fetching link image too, which worked with WAMP, but that also didn’t work.
Any clue ?
There is no ColdFusion code in your sample (apart from #request.serverCustom#). IN which case you don’t need to bracket the whole dang script. Put outputs around just those variables as such.
And then inside the JS:
Bracketing the whole thing will work, but it seems messier to me (although others will prefer it).
If you ARE having an issue with CF it is likely this var that is the issue. Load your page and go to “view source” – check out the HTML that is rendered. If the path to your jquery-1.3.2.min.js and simplgallery.jas files are screwed up then you need to fix it by adjusting the #request.serverCustom# variable – or by adding a slash or whatever.
I usually copy out from view source and load the path in my browser to see what I get (adjusting for relative vs absolute of course.
If it’s something else I’m afraid we will need a bit more information. What is it actually doing?