I have a list of training dates saved into an XML file, and I have a little javascript file that parses all of the training dates and sp开发者_运维问答its them out into a neatly formatted page. This solution was fine until we decided that we wanted another web-page on another sever to access the same XML file.
Since I cannot use JavaScript to parse an XML file that's located on another server, I figured I'd just use an ASP script. However, when I run this following, I get a response that there are 0 nodes matching a value which should have several:
<%
Dim URL, objXML
URL = "http://www.site.com/feed.xml"
Set objXML = Server.CreateObject("MSXML2.DOMDocument.3.0")
objXML.setProperty "ServerHTTPRequest", True
objXML.async = False
objXML.Load(URL)
If objXML.parseError.errorCode <> 0 Then
Response.Write(objXML.parseError.reason)
Response.Write(objXML.parseError.errorCode)
End If
Response.Write(objXML.getElementsByTagName("era").length)
%>
My question is two-fold:
- Is there are a way I can use java-script to parse a remote XML file
- If not, why doesn't my code give me the proper response?
Is there are a way I can use java-script to parse a remote XML file
To get around SOP restrictions, you can do it the same way, as it's done with JSONP (just send XML instead)
http://en.wikipedia.org/wiki/JSONP#JSONP
So you would (maybe dynamically) insert a script tag in your page:
<script type="text/javascript"
src="http://otherdomain.com/getXml?jsonp=parseXml">
</script>
And the server would return this content:
parseXml("<?xml version=\"1.0\">...");
Then you only have to define a parseXml(xmlStr)
function in your script (but I think you already have one).
精彩评论