开发者

How to parse XML with jQuery on a local computer?

I'm new to XML and I want to learn how to parse XML with jQuery. I've followed this example http://www.vagrantradio.com/2009/10/how-to-parse-xml-using-jquery-and-ajax.html, and I even downloaded the demo, but it didn't work on my computer.

However, when I uploaded the demo to a remote server, everything worked fine. S开发者_Go百科o my question is, is there a way to parse a XML with jQuery on a local computer? I'm asking this because it's a lot simpler for me to practice XML without constantly uploading files to remote sever. As for the local testing, I've tried using the WAMP server but with no luck, so is there a way to text XML parsing with jQuery on my local computer without uploading to the remote server?


Depending on the browser you use, you can run into some security features that prevent you from using File API/XHR on the file:// protocol (I had the problem with Chrome).

How are you loading the xml file?

A simple solution would be to use a simple http server, with python for exemple:

python -m SimpleHTTPServer 8000


You could use jsfiddle.net. Personally I use it to write and test quick javascript prototypes because all I need is a web browser. It also allows you to test AJAX requests. Here's one demo I wrote for you that you could enhance.


When you're viewing a web page from the local filesystem, make sure your refs are correct. For example:

src="/path/to/jquery.js"

Should probably be changed to:

src="c:\path\to\jquery.js"

An absolute URL should always work, like:

src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜