How do I FORMAT Ajax to POST

Get help using Construct 2

Post » Wed Aug 20, 2014 4:32 pm

Hi I am trying to work out how to use Ajax and I am stuck on the POST side of the line for Construct2

the lane I have is,

Code: Select all
"http://mywebsite.com/ajaxTrain/postIn.php?Username="& Username.Text &"&Password=" & Password.Text


the Ajax"on completed" action gets triggered how ever when i look into the base there's nothing there.
I have also echoed out the data to another part of the screen that is being sent to the .php
after the Ajax is called and that computes right,
B
13
S
4
Posts: 60
Reputation: 1,001

Post » Wed Aug 20, 2014 4:47 pm

I'm having similar problem here (similar, not the same):
problem-with-the-ajax-on-complete-and-on-error-triggers_t113024
B
4
Posts: 12
Reputation: 218

Post » Wed Aug 20, 2014 5:34 pm

Kniggles wrote:Hi I am trying to work out how to use Ajax and I am stuck on the POST side of the line for Construct2

the lane I have is,

Code: Select all
"http://mywebsite.com/ajaxTrain/postIn.php?Username="& Username.Text &"&Password=" & Password.Text


the Ajax"on completed" action gets triggered how ever when i look into the base there's nothing there.
I have also echoed out the data to another part of the screen that is being sent to the .php
after the Ajax is called and that computes right,


this is the .php
Code: Select all
$Username = mysqli_real_escape_string($con, $_POST['Username']);
$Password = mysqli_real_escape_string($con, $_POST['Password']);


$sql="INSERT INTO members (username, password)VALUES ('$Username', '$Password')";
B
13
S
4
Posts: 60
Reputation: 1,001

Post » Wed Aug 20, 2014 6:47 pm

If your running your capx in preview mode and not running from the same the server the AJAX file (postIn.php) is located on, then your server will by default ignore the ajax request. Its a security function of php to prevent outside connections from accessing any data you don't want them to. On your AJAX file you need to add a header call to allow access from out side connections.

Code: Select all
<?php header('Access-Control-Allow-Origin: *'); ?>


How ever you need to do more reading on this subject as this line above will open up your server to all outside requests. Its dangerous to leave it in place as is but for testing this should fix your problem
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Wed Aug 20, 2014 7:17 pm

I just use: https://chrome.google.com/webstore/deta ... ihlkkiljbi

Worked like a charm when enabled.
ImageImageImageImage
B
62
S
19
G
51
Posts: 633
Reputation: 30,836

Post » Wed Aug 20, 2014 10:56 pm

You don't include the values as part of the URL in a POST request. Put them in the data field:
post.PNG
You do not have the required permissions to view the files attached to this post.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,680

Post » Thu Aug 21, 2014 12:01 pm

ramones wrote:You don't include the values as part of the URL in a POST request. Put them in the data field:
post.PNG

Not Only is that a lot simpler it also works :)
thank you very much " ramones "
B
13
S
4
Posts: 60
Reputation: 1,001

Post » Tue Aug 26, 2014 7:03 am

Kniggles wrote:
Kniggles wrote:Hi I am trying to work out how to use Ajax and I am stuck on the POST side of the line for Construct2
this is the .php
Code: Select all
$Username = mysqli_real_escape_string($con, $_POST['Username']);
$Password = mysqli_real_escape_string($con, $_POST['Password']);


$sql="INSERT INTO members (username, password)VALUES ('$Username', '$Password')";


You've probably figured it out now, but '$Username' takes the string literally (when using single quotation marks), it should be "$Username", and in this case it may also simply be $Username as other text isn't appended to the string.
B
32
S
7
G
2
Posts: 317
Reputation: 2,851


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot], LunaticCat and 2 guests