AJAX and XML

Get help using Construct 2

Post » Wed Aug 15, 2012 10:55 pm

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?
B
6
Posts: 4
Reputation: 660

Post » Wed Aug 29, 2012 4:15 am

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..
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

Post » Wed Aug 29, 2012 12:13 pm

Your XML is invalid. It's missing the required start tag at the top (<?xml ...)
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,498

Post » Wed Sep 19, 2012 10:29 pm

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.
B
6
Posts: 4
Reputation: 660


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests