How do I post data using AJAX?

0 favourites
From the Asset Store
We present to you “Post Apocalyptic Trailer” – our newest hard hitting, bass rumbling designed movie trailer collection.
  • Your C2 Version doesn't matter.

    PHP stopped ... hm ^^ You should try to upload all stuff to a different server.

    You have done everything right and it should work.

  • FIXED!

    The reason PHP stopped was because I was messing with folder (not file) permissions and infact this WAS the root cause of the initial problem.

    For some reason, once I messed with the folder permissions the AJAX calls now work from inside the html page.

    Got there in the end. Hopefully this will help someone in the future too.

    Thanks again!

    <img src="smileys/smiley32.gif" border="0" align="middle" />

  • Mission accomplished. <img src="smileys/smiley42.gif" border="0" align="middle" />

  • I followed this thread and it didn't work to me, sometimes it gave me errors like 500 and [an error occurred while processing this directive]

    Would you help me step by step?

  • Where do you capture this error messages?

  • Prox I was using Chrome console, i will take my time to research how to post data, if it works it will return to you where you filled an e-mail field.

  • If you want a return message from AJAX:"Request URL" your php script should generate some output, like:

    echo "done";

    or if you want return the number of bytes that were written to the file:

    $bytes = file_put_contents("data.txt", $_GET['myVar']);

    if($bytes !== false){ echo $bytes; }else{ echo "failed"; }

    I suspect your error messages are based on incorrect web-server settings.

  • Prox would it be possible to post (upload) and image/screenshot from the guy this way?

  • Hi,

    I m new to novice to construct 2, I'm using constuct r178 release.

    I have created one capx file for the example .

    basically file is used to send textbox value to the php page via POST method and that data is stored into the database.

    By doing so I am facing some error because of that I'm not able to retrieve the data in the php file.Please suggest me the solution

    Here is the php code for the reference


    /*db connection menthod*/

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

    $query = mysql_query("insert into score (`score`)values('".$_POST['score']."')");


    echo "done";


    echo "notdone";


    /*getting error of */

    Notice: Undefined index: score in

  • You can fix the error by checking the $_POST['score'] variable exsits, so before your query you can use

    if(isset($_POST['score'])) {

    $score = $_POST['score'];

    } else {

    $score = 0;


    and then use the $score variable in your query, this wont fix the reason the $_POST['score'] variable isnt being sent, but its always best to check whats being sent and also in your case make sure its a number to stop people doing stuff they shouldnt be able to.

    if(isset($_POST['score']) && is_numeric($_POST['score'])) {

    $score = $_POST['score'];

    } else {

    $score = 0;


    I'm working at the moment so cant have a look at the capx, I will try and help when finished.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • of course I can do that but right now my problem is I m not able to get the post data in the post method , please see the example which I have attached.which will be more explanatory.


  • Apologies., I did also explain that it doesnt solve that issue and that im at work so couldnt do that part with the capx...

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