How do I Retrive Data from Ajax POST

0 favourites
  • 5 posts
From the Asset Store
We present to you “Post Apocalyptic Trailer” – our newest hard hitting, bass rumbling designed movie trailer collection.
  • 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.

    <?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";
    }
    ?>[/code:qxhqrrlp]
    
    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,
  • 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: *');

  • Bingo! Thanks so much, totally forgot about that.

  • 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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • > 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.

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