How do I Retrive Data from Ajax POST

Get help using Construct 2

Post » Mon Oct 05, 2015 3:03 am

I'm using AJAX to send data to a php file on my server.

Sending URL looks like this.
http://elf-games.com/twitch/checklogin. ... ss=texas18

The php file on server is this. Obviously the ***** are data I don't want to show, but the connection is working fine.

Code: Select all
<?php

$host="localhost";
$username="*******";
$password="********";
$db_name="*******";
$tbl_name="********";

mysql_connect("$host", "$username","$password")or die("cannot connect");
mysql_select_db("$db_name")or die ("cannot select DB");

$myusername=$_GET['user'];
$mypassword=$_GET['pass'];

//to project MySQL injection
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql = "SELECT * FROM $tbl_name WHERE name='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){
   $_SESSION['myusername']=$myusername;
   $_SESSION['mypassword']=$mypassword;
   echo "Success";
   //header("location:login_success.php");
   
} else {
   echo "Wrong Username or Password";
}
?>


I assumed the Echo responses are what would give me back my ajax.lastdata, but I'm getting nothing back. Any ideas how I send data back to my ajax call?

Thanks,
B
101
S
32
G
11
Posts: 1,552
Reputation: 21,667

Post » Mon Oct 05, 2015 11:33 am

You are likely getting an error in your networking overview stating you are not allowed to use that resource.

Please add the following line to the top of your PHP page and try again:

header('Access-Control-Allow-Origin: *');
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,567

Post » Mon Oct 05, 2015 1:48 pm

Bingo! Thanks so much, totally forgot about that.
B
101
S
32
G
11
Posts: 1,552
Reputation: 21,667

Post » Sun Jun 19, 2016 5:19 pm

lennaert wrote:You are likely getting an error in your networking overview stating you are not allowed to use that resource.

Please add the following line to the top of your PHP page and try again:

header('Access-Control-Allow-Origin: *');


Sorry for question on old post, but what does this do exactly?

Or more simply

Should it be used in all php scripts/pages in association with Construct?

I am troubleshooting an issue with an AJAX POST from Construct. I added this and it didn't solve the issue so don't know whether it's safe to leave in or may cause more issues.

Brief answer is fine as if I want the nitty gritty I assume I can read here https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
ImageImageImage
B
39
S
22
G
11
Posts: 492
Reputation: 9,925

Post » Fri Jun 24, 2016 6:48 am

badmoodtaylor wrote:
lennaert wrote:You are likely getting an error in your networking overview stating you are not allowed to use that resource.

Please add the following line to the top of your PHP page and try again:

header('Access-Control-Allow-Origin: *');


Sorry for question on old post, but what does this do exactly?

Or more simply

Should it be used in all php scripts/pages in association with Construct?

I am troubleshooting an issue with an AJAX POST from Construct. I added this and it didn't solve the issue so don't know whether it's safe to leave in or may cause more issues.

Brief answer is fine as if I want the nitty gritty I assume I can read here https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS



That piece of code allows posting methods (also ajax posts/gets) from a different domain then where the php page itself resides.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,567


Return to How do I....?

Who is online

Users browsing this forum: David181, OBLIVION, senecaa and 13 guests