Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation Can you randomly load xml items or files with java?

    This is a weird idea I have- i will try to explain it all (forgive me if i do not).

    i'm using xml to create dynamic content on the site i'm building for myself.
    now, i know there is a way to randomly load xml content using php-
    but i have zero experience with php (though i not afraid to learn it, if it is the only way to do this).

    here's what i want to do:
    i have (let's say) 4 "announcement" areas on a page, in addition to a "random info" bar off to the side. in each of these, i want to have randomly loaded xml content each time the page is refreshed/viewed.

    so if i have a "recent site news" section on the page, i would have a folder for "some code" to look in to pull out an xml file to display. etc etc.

    basically, i'm wondering if there is a java way to do this (perhaps similar to the choosePic function?). it doesn't have to load a different xml file each time the page is refreshed either- if there's a way to pick a set number of items from any xml file i specify- that would be ok too.

    any help would be greatly appreciated.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    This is the JavaScript forum. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names.

    JavaScript is purely a client-side language, and unless used with an Ajax call has no capability to read from or write to a file (except a cookie), communicate with the server, access a database, the client's operating system or the Windows registry, or alter the default behaviour of the browser.


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

  • #3
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    my apologies for not using the full term and confusing you. i am talking about javascript.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Philip's answer was not only correct but it also makes a real difference in your question.

    Yes, what you want to do is easily possible with JAVA.

    Java has all the capabilities of PHP and then some.

    What you want can *NOT* be done using JavaSCRIPT *UNLESS* the XML file(s) in question are from the SAME DOMAIN as the web page that is attempting to read them.

    JavaSCRIPT does *NOT* support "cross site scripting" or "cross site access".

    So you see, it makes a huge difference.

    *ARE* you talking about XML files from the same domain? If so, then yes, you can do this. Not too hard, either. And if you just look in this forum, this same question was answered within the last week or two, I'm pretty sure. If I'm wrong though, or if you can't find the relevant answer and code, ask again. Assuming these are same-domain files.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    yes, they are all from the same domain.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Then, yes, you certainly can do this.

    After all, that's exactly what AJAX is all about: Asynchronous Javascript And Xml.

    Tons and tons of articles on AJAX out there. Tons of examples.

    If you want to do this at page load time, you might not need to use the "A" in AJAX. You can use Synchronous calls, instead.

    Oh, w.t.h. ... let me find a tutorial...

    http://www.w3schools.com/ajax/default.asp

    Look especially at this page:
    http://www.w3schools.com/ajax/ajax_x...quest_send.asp

    and if you want to do this at page load time, look at the section that is titled "Async = false"
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    onkodjinn (07-28-2010)

  • #7
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    the second link sounds like a concept that could definitely work out, from what i've read so far. i'll have to try it out. thanks old pedant!

    i've uploaded the "template page" i made to try this idea out at http://onkodjinn.vacau.com/ if you want to see what i originally started with.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •