AJAX upload restrictions?

0 favourites
  • 10 posts
From the Asset Store
You can upload screenshots and photos to your server very easily.
  • I note that whenever I submit an AJAX to website (to store data, such as leaderboards) there are occasions where I was unable to actually upload anything.

    I asked this question over a year ago to a deadly silence, but hopefully someone can help out this time...

    https://www.construct.net/en/forum/construct-2/general-discussion-17/ajax-post-limit-143358

    After some investigation, it seems that the problems come when I post anything that includes a symbol, such as & or #. This blocks the upload of data entirely!

    I'm able to get around this by using the replace action, that replaces the symbols with words. For example, # becomes !hash! and & becomes !and! (apparently ! is not an issue).

    However, I'm worried that I will end up missing a symbol somewhere along the line, especially with there being dozens of them.

    Can anyone think of a clever way of encrypting the data that's uploaded (that is ajax/php safe) then decrypting it when Construct downloads it again?

  • How does the data you are sending look like?

  • Hey DiegoM

    As an example, it's basically a series of JSON codes embedded into a single JSON.

    {"c2dictionary":true,"data":{"MiniWidth":480,"MiniHeight":280,"MiniX":1440,"MiniY":800,"ModData":"{\"c2dictionary\":true,\"data\":{\"and4d\":0,\"challacc\":0}}","GiveawayData":"{\"c2dictionary\":true,\"data\":{\"MaxEntries\":100,\"Word\":\"! \"}}","CounterData":"{\"c2array\":true,\"size\":[0,2,1],\"data\":[]}","StoreData":"{\"c2array\":true!comma!\"size\":[1!comma!3!comma!1]!comma!\"data\":[[[\"Scribble \"]!comma![\"ScribblePlus\"]!comma![\"50\"]]]}"}}

    This is then uploaded via AJAX, calling a php file which stores it into a database.

    If any section of the data includes a comma, it breaks the json (which makes sense), yet if I use certain symbols it breaks the upload, and it never reaches the database.

    I'm currently in the process of testing an encryption plugin, but I always hate using non-official plugins in Construct 3.

  • Have you tried setting the "Content-Type" header to "application/json" before making the request?

    If you are not doing that, then it must be trying to send as plain text, and then you need to escape certain special characters. But I am just vaguely recalling all of this, so it might not be accurate.

  • No, but I will try that asap and then get back to you!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • have you tried "urlencode" before sending the text? you will then need to urldecode in php on the other end.

  • Have you tried setting the "Content-Type" header to "application/json" before making the request?

    If you are not doing that, then it must be trying to send as plain text, and then you need to escape certain special characters. But I am just vaguely recalling all of this, so it might not be accurate.

    It seems to have a problem submitting commas. It posts the word just after the comma, then stops. I'll try the ecryption approach. Kinda makes sense for stored data to be encrypted anyway. Hopefully Construct gets an official plugin soon.

    have you tried "urlencode" before sending the text? you will then need to urldecode in php on the other end.

    I have not. I will do that if the encryption plugin fails :D

  • I would try urlencode first - it converts commas, &, ?, and all the other symbols to codes that cause trouble in URLs. then urldecode converts them back.

  • there might be a chance that the encryption adds symbols that cause trouble.

  • I would try urlencode first - it converts commas, &, ?, and all the other symbols to codes that cause trouble in URLs. then urldecode converts them back.

    This has worked perfectly AllanR

    I'm tempted to try the encryption at some point as well, but I'll keep it in my back pocket for a while!

    Thank you so much for your help!

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