Dynamic Image request troubles (AJAX, Dropbox...!?)

Get help using Construct 2

Post » Tue Aug 19, 2014 3:10 pm

I'm finding it hard to troubleshoot this issue. Any thoughts?

I'm testing out the AJAX functionality to implement into a Social sharing feature. I want to retrieve an image from the server (this cannot be just a project file, as the image to retrieve will change so will need to be able to change the URL via a variable.) and for testing purposes, load it into a sprite here. I'll later expand on this to pass the AJAX response to a share plugin in order to post an image to a user's feed/wall/etc.

In the capx below, the first text version works fine, but the second image version isn't working.

It appears that the AJAX request has run successfully (as notified by the "SUCCESS!" text), however the image is not being loaded into the sprite using "AJAX.LastData".

Below is the event sheet.

Image

Here is a live demo: http://dev.angelserver.in/construct2_test/AJAX_TEST/

Capx is here: http://dev.angelserver.in/construct2_te ... _test.capx
Last edited by angellondon on Mon Sep 01, 2014 11:48 am, edited 1 time in total.
B
7
S
1
Posts: 61
Reputation: 588

Post » Tue Aug 19, 2014 3:59 pm

hi, I tested this with IE11, when I clicked the image I got a pop-up. when I enabled that, I got

http://dev.angelserver.in/construct2_test/AJAX_TEST/���JFIF
The webpage cannot be found

firefox reported
"Firefox can't find the file at http://dev.angelserver.in/construct2_test/AJAX_TEST/����."

I'm not able to upgrade to 177 at the moment so I can't look at your capx... but I suspect something has gone wrong. The special characters are a bad sign at least..
B
7
S
3
G
1
Posts: 184
Reputation: 1,352

Post » Wed Aug 20, 2014 11:04 am

Thanks for your reply! Yes, I'm rendering the same result, thanks for confirming it.

I haven't been able to retrieve an error message that's more meaningful unfortunately, so haven't had much luck in further debugging it :(

Am I using the wrong sort of AJAX request? I'm using "Request URL", for which the help text reads "Request a URL by a GET request and retrieve the server response."
B
7
S
1
Posts: 61
Reputation: 588

Post » Wed Aug 20, 2014 12:28 pm

What are you trying exactly ?
B
32
S
10
G
3
Posts: 310
Reputation: 6,081

Post » Wed Aug 20, 2014 3:30 pm

Thanks for your reply @stctr. Ok, for testing purposes, this is what I'd like to happen:

1. Click img sprite button
2. AJAX calls an image file from the server (crucial that I can set this dynamically - it cannot just be a part of the project files)
3. Upon AJAX load complete, the so-far-empty sprite named 'imgReturnedData' should load the image called by AJAX (LastData).

For the final app, this will be expanded somewhat:

1. User creates their user content (in this case, it will be a mugshot generator which they can upload their own photo to. Functionality-only version here: http://www.angelserver.in/html5/mugshot_generator/ )
2. Upon completion, their image is uploaded to our database using a filename generated within the app
3. The user might want to share the completed image on Facebook, Twitter etc, so they click on the particular 'share'
4. AJAX makes a call to our database to retrieve the user-generated image
5. AJAX.LastData is used to pinpoint the share function to the particular image URL on our database. i.e. Image: "http://our.server/images/" & AJAX.LastData & ".png"
B
7
S
1
Posts: 61
Reputation: 588

Post » Wed Aug 20, 2014 4:59 pm

Saving files to your server can actually increase the security risks if not done properly. If you want to save an image to your server, why not save the imagedata string to a mysql database. This would avoid all the file i/o errors that you can generate and decrease the security risks to your server assuming your mysql calls are done correctly. :)
www.h1k3.tech

We are here for you!
B
87
S
23
G
16
Posts: 715
Reputation: 16,835

Post » Wed Aug 20, 2014 8:59 pm

I did consider this; I've just been exploring my options really. Can you point me in the direction of some resources on this so I can try it out?

My SQL is alright, but I'm not sure where to start, integrating it into a Construct 2 application :) thank you @lanceal , for your suggestion.
B
7
S
1
Posts: 61
Reputation: 588

Post » Wed Aug 20, 2014 9:42 pm

A wonderful resource for you especially if you are new is phpclasses.org. It is a wealth of ready made code that you can plug into your website. http://www.phpclasses.org/browse/ will let you browse the available code by category. You want to add a user login/registration they have it under user management. You want file I/o it's there too. Of course they have a whole section on MySQL too. Make sure to give the authors credit if you use their functions. :)
www.h1k3.tech

We are here for you!
B
87
S
23
G
16
Posts: 715
Reputation: 16,835

Post » Thu Aug 21, 2014 9:07 am

Thanks @lanceal ! I will check it out and see how it goes. If I arrive at a solution using this method, I'll post it here to share it with the community.

Any ideas why my original execution with AJAX didn't work out, however? I'd still like to know.
B
7
S
1
Posts: 61
Reputation: 588

Post » Thu Aug 21, 2014 9:46 am

Oh my, I just converted a test image (a black and white 512px × 608px PNG) to a base64 string, and it came out at 700,046 characters!

Is this expected? Is a string this large an appropriate size to be stored in a database? It slowed my browser right down.
B
7
S
1
Posts: 61
Reputation: 588

Next

Return to How do I....?

Who is online

Users browsing this forum: zenox98 and 24 guests