How do I, use POST method with Ajax and PHP DBOperations?

Get help using Construct 2

Post » Wed Oct 05, 2016 2:27 am

Hey,
I'm new to the forums, so sorry for not posting screenshots of the problem.
I have been trying to make a PHP/Mysql, database to create a login.
I completed like 3 tutorials on the web, and the ones here, like "Simple Login using a MySQL database", and "Creating your own Leaderboard / Highscores easy and free (PHP MySQL)"

After quite some research and failures, I figured that "Fatal error: Uncaught Error: Call to undefined function mysql_connect()"
has to do with some deprecated functions of a old PHP, and now people use the DBOperations.

So, I'm following a Android tutorial on "learn2crack" website, with the name "Android Login Registration System with PHP and MySQL (Updated) – Server #1"...

I have set up, all the server, database, php files etc. And I'm using Postman, to POST, this request to the server:

Code: Select all
{
   "operation":"register",
   "user":{
        "name":"Raj Amal",
        "email":"[email protected]",
        "password":"rajamalw"
   }
}



My question is, the code above, the Register Operation, How I POST that, using Construct 2 events?

I tried a Event like this:
Mouse, On left button clicked, on Sprite, AJAX, Send "" to URL "http://127.0.0.1/polar/savescores.php?name=" & txtPlayerName.Text & "&score=" & Score (method "POST", tag "PostScore").

But that is not working, anyone has any suggestions?
Last edited by thiago28x on Wed Oct 05, 2016 12:58 pm, edited 1 time in total.
B
7
S
1
G
1
Posts: 7
Reputation: 889

Post » Wed Oct 05, 2016 9:28 am

Your elements like
Code: Select all
"score=" & Score


Should be in the "Send" field of the request, not the URL.
Also never forget AJAX cross-domain request security mentioned in the manual article.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
292
S
115
G
96
Posts: 7,295
Reputation: 70,795

Post » Wed Oct 05, 2016 3:27 pm

Hey! Thank you for replying! :)

I did put the "score=" in the Send field, I guess..
Gonna give one more try today after work :)

(need to assure the "Access-Control-Allow-Origin: *" is ok on the header.. I'm not a programmer so I take sometime to figure out where to put the codes and lines lol)

I attached CAPX files to google drive here:

https://drive.google.com/drive/folders/ ... sp=sharing
B
7
S
1
G
1
Posts: 7
Reputation: 889


Return to How do I....?

Who is online

Users browsing this forum: Artcadev, brunopalermo and 31 guests