Sending data via Ajax to Save in MySQL Failed

0 favourites
  • 9 posts
From the Asset Store
Forget about default textbox restrictions, you can create sprites atop of the textbox
  • Link to .capx file (required!):

    leiron.be/exttopics3/test

    Steps to reproduce:

    1. vinsky2007eqs@gmail.com

    2.

    3.

    Observed result:

    Sending the data via AJAX POST the parameter is not able to send to the PHP script to save the parameter passed which are taken from Input Form, but it is writing blank which means the parameter (data) was not send.

    I followed the sample.   Yes, database table had been created and connection is valid but it is writing blank.

    Expected result:

    Insert parameter passed which was a Name and a Message (text) field into the Table with the values in it

    Browsers affected:

    Chrome: yes

    Firefox: yes

    Internet Explorer: yes

    Operating system & service pack:

    Windows 7 Starter

    Construct 2 version:

        

    version r127

  • Closing, no .capx provided. For this type of bug you ought to share the server-side code you're using as well in case there's a problem with that. AFAIK lots of people are using the AJAX object to post and get successfully, so I'd double check the problem isn't your end.

  • You don't need to include the ? in the data field.

    <img src="https://dl.dropboxusercontent.com/u/8367729/construct/pics/ajaxPost.PNG" border="0" />

  • Hi,

    Sorry, the said file can be downloaded in the link below (just uploaded).

    leiron.be/exttopics3/test/input-form-ajax.capx

    The PHP code is below (from the file record-msg.php):

    <?php

    /**

    * AUTHOR Vinson Tan

    * 2013

    */

       session_start();

       

       $vin = "../connect.php";

       if ( file_exists( $vin )) {

          require( $vin );

       } else {

           $vin = "connect.php";

           if ( file_exists( $vin )) {

              require( $vin );

           } else {

                $vin = "../../connect.php";

                if ( file_exists( $vin )) {

                   require( $vin );

                } else {

                      $vin = "../../../connect.php";

                      if ( file_exists( $vin )) {

                         require( $vin );

                      } else { echo "Sorry, $vin was not found  "; }

                   }

            }

         }

       

       $fname = $_GET['fname'];

       $fmsg = $_GET['fmsg'];

       

       $sqlstr = "insert into construct_user_list (playerid, msg) values ('".

                  $fname.

                 "','".

                  $fmsg.

                 "')";

       

       mysql_query( $sqlstr );

       

       mysql_close($conn);

       

    ?>

    Thank You.

    Vins

  • Hi,

    I have just corrected and uploaded a new version where I have removed the "?".

    However; i am getting a " Refused to set unsafe header "Content-Length " when I use the Developer Tools -> Console.

    Please advise as i am still writing blanks.

    Thank You very much.

    Vins

  • That should be $_POST not $_GET :)

    You're right, there is a console error in Chrome but it still seems to be making the request successfully. (@Ashley http://stackoverflow.com/questions/2623963/webkit-refused-to-set-unsafe-header-content-length)

  • Hi,

    Yes, i made the changes on my localhost and it is working even if the said Error from console is there.

    I am also trying to Request data off the server-side the PHP script is below (for return-msg.php):

    <?php

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

    echo "This is a Return value from an AJAX call...";

    ?>

    I have added the lines below in the Project file (sorry, i have not uploaded an updated copy yet but i will as soon as i have a chance too).

    AJAX

    Request "http://localhost/testing-only/return-msg.php"

    Tag

    "GetData"

    Then, I added

    AJAX

    on "GetData" completed

    returnText (text)

    Set text to AJAX.LastData

    However; i am not able to receive the said Echo'd string message.

    Please advise and Thank You again for the much support.

    Is there a list of updated Tutorials that i can work with ?

    Thank You very much again for the much support.

    I like the product very much and will be getting my own copy soon, i just wanted to know more about the said product as i am an urgent little game that i wanted to work on and needed to know more about the data handling side.

    Kind regards.

    Vins

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Server configuration is out of the scope of this forum. You'll need to ask on a more relevant site e.g. StackOverflow. Note the server must send the header "Access-Control-Allow-Origin: *" in order to permit requests from any origin.

  • Hi,

    Yes, it is working having the header('Access-Control-Allow-Origin: *'); added does it.

    Is there a possibility to resolve the Error(s) found in the console ?

    Thank You.

    Vins

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