getting xml file to be local within wordpress XMLHttpRequest
i am parsing an xml file with the script:
window.onload = usdfunction;
if (window.XMLHttpRequest)
{// code for IE7+, Fi开发者_JS百科refox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","sc2xml.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
and for this type of script to work i heard you have to keep the xml file in a local dictionary as the page... you can't use the full URL, etc.. can anyone confirm or deny this? also where would i place the file so it's local on a wordpress blog? thanks..
I'm not sure what you mean by "local dictionary", but the rule on AJAX requests using XMLHttpRequest
is that the file to be loaded has to fall under the Same Origin Policy, which means:
The domain name must be the same, including subdomains (so you couldn't, for example, load a file hosted on
example1.wordpress.org
in a blog onexample2.wordpress.org
).The protocol (e.g.
http
orhttps
) must be the same.The port must be the same (probably doesn't apply in your case; for example, you can't load a file at
example.com:8080
from a page atexample.com
).
So the short answer is, as long as the XML file is on the same domain as your Wordpress install, you should be fine - you could store it anywhere on the server.
精彩评论