Jump to content
Gilbert

Using AJAX to get info from XML file

Recommended Posts

Hi all,  I'm just starting to get into website design, tho' I've been a programmer for many years.  I've got a site going pretty well, but I really want to update the information on the site every day using tables.   I am studying the AJAX/XML method and I think I must be missing something.   After using the 'display CD collection' as a model, I couldn't get it to work.  So then I tried copying & pasting the actual files from the example ( they list the xml file for your reference ) into a folder and Opened it with a google browser.  I can get the button that says 'create my CD collection', but nothing happens when I click it.  What am I missing; is there another article that might explain this in more detail and say exactly what's going on?  Thanks

Share this post


Link to post
Share on other sites

Open your browser's developer tools and check the console for Javascript error messages.  If you're trying this on your computer just by double-clicking on a file to open it in the browser, that might be the problem.  Browsers have different security models when they communicate with a web server versus when you're just opening local files using file:// or something like that.

Share this post


Link to post
Share on other sites

Hey, justsomeguy - thanx for your response.  I'm am a little hazy ( actually a lot hazy ) on the whole server thing.  I thought I read someplace that if your data file (xml) was in the same folder as your html file that it would work ok.  I've tried putting the whole path for my xml file, like c:\ learningwebdesign\myhtml etc, etc but it still doesn't work.   Do I need to download a server just to experiment with a few things and which ones would you recommend.   It seems like I've read a thousand pages about servers, but they seem to talk to the experienced developer instead of the beginner and I am still wondering if I 'need' a server on my computer before I'm ready to publish to a hosted website.  Can you recommend some server software that will accomplish what I need here, which is just to see if my code works.   Actually the 'code' works - I just can't get to the data it seems.   I know you may be saying that my syntax might be wrong or something like that, but I copy & pasted a couple of programs and they don't work on my set up either.  I hope I've explained what it is I need - Thanks for any help..... Gil

 

Share this post


Link to post
Share on other sites

The issue isn't the location of the files relative to each other, it's how you're accessing them.  If the URL bar in your browser starts with http:// or https:// then your browser uses one security model, if it starts with file:// or anything like that it uses another.  I don't know if ajax even really works for non-HTTP requests, because part of that process is communication with a web server.  It might work, but I wouldn't count on it.  

If you want to download a server for testing, the easiest are packages like XAMPP.  That includes the Apache web server, and also PHP and MySQL and some other tools pre-configured.  After you install that and start Apache, you'll be able to access it at http://localhost/ 

There will be a specific folder on your computer that Apache uses as the document root, that's where the root level of your website is.  So if you create a file and save it in that folder as index.html, you can access it at http://localhost/index.html, or if you put a folder called images in the document root then that will be at http://localhost/images/ etc

 

  • Like 1

Share this post


Link to post
Share on other sites

Thank you very much justsomeguy - that really helped 'splain it.  I'll mark this as answered if I can find where to do it.?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×