How do I FORMAT Ajax to POST

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

    "http://mywebsite.com/ajaxTrain/postIn.php?Username="& Username.Text &"&Password=" & Password.Text[/code:220cf9c5]
    
    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,
  • I'm having similar problem here (similar, not the same):

  • 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,

    "http://mywebsite.com/ajaxTrain/postIn.php?Username="& Username.Text &"&Password=" & Password.Text[/code:2yb1rme8]
    
    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

    $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')";
    [/code:2yb1rme8]
  • 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.

    <?php header('Access-Control-Allow-Origin: *'); ?>[/code:28h0ra1m]
    
    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
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I just use: https://chrome.google.com/webstore/deta ... ihlkkiljbi

    Worked like a charm when enabled.

  • You don't include the values as part of the URL in a POST request. Put them in the data field: [attachment=0:1tu53q9o][/attachment:1tu53q9o]

  • You don't include the values as part of the URL in a POST request. Put them in the data field: [attachment=0:3lpi8ui2][/attachment:3lpi8ui2]

    Not Only is that a lot simpler it also works

    thank you very much " ramones "

  • > 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

    >

    $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')";
    > [/code:3e2k85z8]
    > 
    

    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.

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