Question:
My javascript/jQuery doesn't works! (url problem probably) Any idea?
McCh!cken
2010-01-02 15:29:30 UTC
I have a jQuery code that works with an XML document. It goes well till the xml path changes to an upper directory or a directory that can only be available through using "../". Like:
The HTML that uses my jQuery function is in [html] and the xml is in [xml] directory. The tree:
[html]
-> here is my html file; to access the xml doc: "../xml/myDoc.xml"
[xml]
-> and here is my xml
So I tried file:///... access, absolute url, hasn't worked either...
I can't put my [xml] directory in the [html] one, due to certain reasons.

My jQuery function:
function workXML(xmlFile,mode,data) {
$(document).ready( function(){
$.ajax( {
type: "GET",
url: xmlFile,
datatype: "xml",
success: function(xml) {
alert("jó");
if (mode == "fill") {
fillHTML(xml,data);
addImages(xml,data);
} else if (mode == "cur") {
fillCur(xml,data);
} else if (mode == "pagedata") {
getPageData(xml,data);
} else if (mode == "getdata") {
return getXMLdata(xml,data);
} else if (mode == "link") {
alert("jó");
return Link(xml,data);
} else {
$("body").append("

Hibás workXML() mode érték!

");
}
}
});
});
}

At the fifth row, I should declare the path of my xml doc, but it doesn't work, the success function does not run.
Have you got any idea how I can keep my directory tree while I can access my xml?
(As I have mentioned the source of the problem is the url, more accurately, the "../".)
Thanks in advance.
Three answers:
anonymous
2010-01-02 18:31:40 UTC
Do not use a path like file:///c:/... unless you are running it locally. If online, use of "../xml/myDoc.xml"" is ok as long as that is the correct relative path in relation to the file that's calling it and the "myDoc.xml" file. These "../" will work locally provided you are mirroring the EXACT online directory structure on your computer. Sometimes you have to add something like "../../xml/myDoc.xml" or "../../../xml/myDoc.xml" to get the correct relative path. That's why it's best that all files are set up on your computer initially with the same directory structure as you will use online.



Not that familiar with this, but make sure you do not have to escape any characters or tags. Example: [ (<\/p>" ]



Ron
anonymous
2010-01-02 16:44:39 UTC
Wow that is some advanced stuff. If I'm understanding your question right, the "../" drops you down a limb on the dir tree. Take that out and you should be good. -"xml/myDoc.xml"



Example:



c:\\server\html\xml

"../" is dropping you down in to the c:\server directory.



Hope this helps
anonymous
2016-11-03 01:41:20 UTC
deliver that reproduction to 3 vast IIT's or to 3 government sector unit which inspires examine issues for this reason they'll placed up ur examine...even einstein initially sent his new imaginative learn of three copies and grew to alter into known ,u too flow in that far extra valuable u examine that article of einstein..do sell that formulation to 3 company after exhibiting it experimentally or u in simple terms build a company ...all the suited


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...