AJAX and XML

0 favourites
  • 4 posts
  • I'm trying to make a quiz game where the list of questions is easily replaceable. To do this, I made a list of questions and formatted it in an xml document, but I don't know how to make it display. The document looks like this:

    <body>

    <question id="1">

    <heading>In what month did the Mars Curiosity rover land?</heading>

    <correct></correct>

    <incorrect></incorrect>

    <answer id="1">March</answer>

    <answer id="2">May</answer>

    <answer id="3">August</answer>

    <answer id="4">September</answer>

    </question>

    <question id="2">

    <heading>What was the chance against the success of the Mars Curiosity rover?</heading>

    <correct></correct>

    <incorrect></incorrect>

    <answer id="1">10%</answer>

    <answer id="2">20%</answer>

    <answer id="3">30%</answer>

    <answer id="4">40%</answer>

    </question>

    </body>

    On the start of the layout, I have AJAX request "questions.xml", then On "Questions" completed, I have XML Load XML document from string "AJAX.LastData" and then I Set Text to Questions.StringValue("/body/question[id=1]/heading/").

    Unfortunately, nothing displays, but I know AJAX.Progress is 1.

    I'm sure I'm not referencing the XML correctly; does anyone know the correct way to do this?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Try first add the entire xml code to the LOAD action in the XML object

    remember to add "" at the beginning and at the end and add two instead of one " inside the code.

    example:

    "<test name=""test"">

       <testing>

       </testing>

    </test>"

    after that, test your event again, if work, then the problem are with AJAX trying to get the content of your xml, if it doesn't work then your .xml file may be not okay or your events might be with something wrong..

  • Your XML is invalid. It's missing the required start tag at the top (<?xml ...)

  • Thanks guys, sorry I took so long to get back on this. I was working on this furiously as it was the last day of my internship.

    It turns out I was trying to pass the name of the document to AJAX as a string, so I was using quotes where I shouldn't have been. That always gets me. Thanks for your help.

    Also, happy International Talk Like a Pirate Day! I'm sure this is really big across the pond.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)