How do I perform a simple 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.
  • Hello, I've managed to make the Get with ajax to work, now i'm trying to Post some data and I'm getting errors.

    Here is how my php file looks like:

    header("Access-Control-Allow-Origin: *");
    
    $user = "root";
    $pass = "";
    
    $dbh = new PDO('mysql:host=localhost;dbname=dbname', $user, $pass);
    
    $Login = $_POST['L'];
    $PW = $_POST['S'];
    $datum = '{"c2array":true,"size":[3,10,1],"data":[[[0],[0],[0],[0],[0],[0],[0],[0],[0],[0]],[["Fatso"],[1000],[100],[900],[10],[10],[39],[10],[10],[0]],[[0],[0],[0],[0],[0],[0],[0],[0],[0],[0]]]}';
    
    $sql = $dbh->query("UPDATE registration SET data = '$datum' WHERE uemail = '$Login' AND upassword = '$PW'");[/code:dpqxiom2]
    
    Here is my construct 2 post request:
    [img="http://s33.postimg.org/7txzoq9gv/image.png"]
    
    At the debugger i'm getting:
    [code:dpqxiom2]Undefined index: L[/code:dpqxiom2]
  • It seems like what you're trying to do is sending data twice (two datas – first in URL field and another time in Data field).

    Try to do like this:

    URL: "http://localhost/legacy/save.php"

    Data: "L=" & UserLogin & "&S=" & UserPass

    I'm not sure what's the savestats.Text inside the Data field.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It seems like what you're trying to do is sending data twice (two datas – first in URL field and another time in Data field).

    Try to do like this:

    URL: "http://localhost/legacy/save.php"

    Data: "L=" & UserLogin & "&S=" & UserPass"

    I'm not sure what's the savestats.Text inside the Data field.

    Thanks for reply, savestats.Text contains json string that must be inserted into the database.

    In other words, the place with $datum, must be provided with the string from savestats.Text

  • Then, I guess, you should add another parameter to the php and to c2

    Example: if you add a parameter $string to php, make Data in c2 to: "L=" & UserLogin & "&S=" & UserPass & "&string=" & savestats.Text

  • Then, I guess, you should add another parameter to the php and to c2

    Example: if you add a parameter $string to php, make Data in c2 to: "L=" & UserLogin & "&S=" & UserPass & "&string=" & savestats.Text

    Thanks a lot! That kept me occupied for several hours.

    Here is how I solved it:

    Undefined index: has been resolved using isset:

    if(isset($_POST['L'])){
        $Login = $_POST['L'];
    
    }else {
        $Login = null;
    
    }
    
    if(isset($_POST['S'])){
        $PW = $_POST['S'];
    
    }else {
        $PW = null;
    
    }
    
    if(isset($_POST['D'])){
        $datum = $_POST['D'];
    
    }else {
        $datum = null;
    
    }
    [/code:1s003siu]
    
    and at construct 2 post I've used the following path on the basis of your suggestion:
    [code:1s003siu]"L=" & UserLogin & "&S=" & UserPass & "&D=" & savestats.Text[/code:1s003siu]
    
    Working like a charm!
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)