Missing '+' on Ajax post

Discussion and feedback on Construct 2

Post » Sat Mar 16, 2013 2:28 am

Hello friends.
I know this might be a php related issues,
But maybe someone can help me :).
I try to post a URI DATA string with the Ajax plugin to a php script, I
request the data and insert it then in my mysql DB,
and almost everything works fine. but my string in the database missing all the '+' sign?
Sorry my bad English,
B
7
S
1
Posts: 8
Reputation: 954

Post » Sat Mar 16, 2013 4:08 am

The + sign is a shortcut for spaces (which can't be used in a url). If you want to use an actual plus sign, be sure to htmlencode the string before sending. It will convert anything that is a special character into it's character code. htmldecode on the php side before inserting into the database.
B
26
S
8
G
3
Posts: 210
Reputation: 5,973

Post » Sat Mar 16, 2013 10:38 am

hey theubie, I owe you a beer.
thank you so much for your prompt response, you were absolutely right and everything works fine now

I found this plugin Extra expressions and could encode my string to a base64 string before sending :) red
B
7
S
1
Posts: 8
Reputation: 954

Post » Sat Mar 16, 2013 1:09 pm

Construct 2 has built-in URLEncode and URLDecode expressions, you need to use them when posting AJAX requests.
Scirra Founder
B
359
S
214
G
72
Posts: 22,951
Reputation: 178,578

Post » Sat Mar 16, 2013 9:22 pm

thanks for the reply Ashley, I think I was too tired :)

but I have now been on google and read a bit about the difference between urlencode VS base64encode and thought I could see that base64encode is better to handle special characters? But I'm not expert in php and do not know if this is a correct way to do it `?
B
7
S
1
Posts: 8
Reputation: 954

Post » Sat Mar 16, 2013 11:17 pm

I use the built in urlencode from C2 to encode and the htmlspecialchars_decode function on the php side for our Ajax transfers for UWE and it works just fine.

Also, just as a side tip make sure you're sanitizing anything you're putting in the database to prevent injection attacks. mysqli_real_escape_string or something similar.
B
26
S
8
G
3
Posts: 210
Reputation: 5,973

Post » Sun Mar 17, 2013 1:39 am

Big thanks to theubie and Ashley, I have now switched to the built-in plugin instead of Extra expression, and it works perfectly. But when my request is very large, I got problems when I tested locally, I have uploaded it to my server and everything works now :)
B
7
S
1
Posts: 8
Reputation: 954


Return to Construct 2 General

Who is online

Users browsing this forum: glerikud and 12 guests