Goal of the script:
Click on link, load an XML and use the content. While al this is happening I want to display a loading image.
 
My first code worked fine in IE and FF but was not generic:
$(document).ready(function(){

$("#loadingImg").hide();

$("#text").hide();

$("#clickMe").click(function(){

$("#text").hide();

$("#loadingImg").show();

var strImg, strText;

$("#loadingimg").show();

var objXml = $.get("loadme.xml", function(xml){

strText = $("text",xml).text();

$("#text").html(strText);

//alert(strText);

strImg = $("img",xml).text();

$("#text").append("<img src="" "+strImg+"\" />");

$("#text").fadeIn();

$("#loadingImg").hide();

}); //end load xml

}); //end click

});//end onload

 
So it has been adjusted that you send the xml path as a parameter and the custom loadXml()  handle the loading of the XML and show the loading.gif.
Well IE handles the next code well, but FF fails:
//Code - Example here: http://www.jmslbam.nl/temp/jquery/xml/ajaxGeneric.html
$(document).ready(function(){
$("#loadingimg").hide();

$("#text").hide();

function loadXml(strPathToXml) {

var _objXml;

$("#loadingimg").show();

var objXml = $.get(strPathToXml, function(xml){

_objXml = xml;

//alert("xmlLoad: " + $("text",xml).text());

});

$("#loadingimg").hide();

return _objXml;

} //end loadXML

$("#clickMe").click(function(){

//hide if the link is going to be clicked more than once.

$("#text").hide();

//load xml

var objXml2, strText, strImg;

objXml2 = loadXml("loadme.xml");

//get text from xml and put it in the html

strText = $("text",objXml2).text();

$("#text").html(strText);

//get the image and put it behind the text

strImg = $("img",objXml2).text();

//alert("click: "+ strText);

$("#text").append("<img src="" "+strImg+"\" />");

//at last show the div#text

$("#text").show();

}); //end click

});//onready

 
The alert in the onclick wont display any text, so it looks like the XML object isnt returned to the click function.
 
Me and my collega's looked at it but can't find out what the problem is.
 
Yours sincerly,

Jaime Martinez

P.S. The image that will be shown has to load, so probably this first time you click it will not display the image. Just click again ;)
P.S. 2 The is a zip if you want to test it local, but remember to start the webserver ;)

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to