How Import AJAX to a string, elegantly?

Discussion and feedback on Construct 2

Post » Mon Aug 31, 2015 11:23 am

I'm testing AJAX for a new project.

When I import a simple string from a project file and use a Text Box and set TextBox.text to AJAX.LastData, it works fine.
If I use a string variable, and say StringVariable = AJAX.LastData, the string ends up blank.
FYI - When I import the AJAX to the textbox, then make the string equal the textbox.text, it works as well.

So I suppose my questions are:
1. What "variable type" is AJAX.LastData? (Seems like an object of some kind and not a string.)
2. Any way to make this work without the XML Plugin?

Thank you! The C2 community is the best!
B
28
S
5
G
2
Posts: 41
Reputation: 2,445

Post » Mon Aug 31, 2015 4:50 pm

Ajax.LastData is generally a textual string.

If you have a Ajax request tagged: "getPage"

On Ajax request done "getPage" set StringVariable = Ajax.Lastdata

The Ajax.LastData needs to be called in the On ajax request done trigger. (or as a sub event)
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

Post » Mon Aug 31, 2015 4:56 pm

thank you @lennaert. unfortunately, i a, aware of all that - and i don't see any way to tag an Ajax request in C2.

https://www.scirra.com/manual/107/ajax.

I'm just wondering what is the simplest way to get Ajax.Lastdata into a string?
B
28
S
5
G
2
Posts: 41
Reputation: 2,445

Post » Mon Aug 31, 2015 5:01 pm

Laughing14 wrote:thank you @lennaert. unfortunately, i a, aware of all that - and i don't see any way to tag an Ajax request in C2.

https://www.scirra.com/manual/107/ajax.

I'm just wondering what is the simplest way to get Ajax.Lastdata into a string?



Did you take your time to read this ?

Read the first thing that comes after "How to make a request".


In your request, I believe its the last entry/option ... there you can add a TAG name.

The info I gave you is what you are asking for.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

Post » Mon Aug 31, 2015 5:13 pm

Apologies. Yes, I see now. But tagging it is irrelevant to this.

On Ajax request done "getPage" set StringVariable = Ajax.Lastdata

That is precisely what I have done but the stringvariable ends up simply being empty.

Why would it be empty? If I say textbox.text = ajax.lastdata, the text transfers easily.
I can then say stringvariable = textbox.text to get the text in the string, but this seems roundabout.

I'm wondering if there's a cleaner way that's all. Thank you for your time helping me figure this out.
B
28
S
5
G
2
Posts: 41
Reputation: 2,445

Post » Mon Aug 31, 2015 5:27 pm

Laughing14 wrote:That is precisely what I have done but the stringvariable ends up simply being empty..



Then either your request is incorrect, or your request does not get you anything.

How do you know stringVariable is empty ? Did you check the debugger ?
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

Post » Mon Aug 31, 2015 5:33 pm

Thanks again - yes, I checked debugger that's how I see the string is empty. I will post a capx later tonight and that should clarify my issue. Thanks for your help, mate!
B
28
S
5
G
2
Posts: 41
Reputation: 2,445

Post » Mon Aug 31, 2015 5:53 pm

There is no reason why it wouldn't work. AJAX.LastData is indeed a string. What device/browser are you using for your tests ? I just tested with Firefox and the "on complete" event sucessfully set my string variable to AJAX.LastData.
B
67
S
28
G
24
Posts: 970
Reputation: 18,675

Post » Mon Aug 31, 2015 11:50 pm

I am using Chrome. This is so weird. I just tried it again and it worked. Below is the code.
Yesterday the text box that I was feeding the string turned up blank in the debugger and in the layout.

Today it works completely as expected. I have no idea what changed between yesterday and today but I have no more questions... for now! :D

Thank you @lennaert and @Magistross for your assistance!

Image
B
28
S
5
G
2
Posts: 41
Reputation: 2,445

Post » Tue Sep 01, 2015 10:55 am

The text object you're trying to show the string in is probably not big enough. The string variable is probably being set correctly.
Scirra Founder
B
387
S
230
G
87
Posts: 24,249
Reputation: 192,240

Next

Return to Construct 2 General

Who is online

Users browsing this forum: Glyfos, jefftrier, Yahoo [Bot] and 5 guests