Sending data via Ajax to Save in MySQL Failed

Bugs will be moved here once resolved.

Post » Thu May 02, 2013 1:44 pm

Link to .capx file (required!):
http://www.leiron.be/exttopics3/test/

Steps to reproduce:
1. vinsky2007@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
B
5
S
1
Posts: 20
Reputation: 545

Post » Thu May 02, 2013 2:07 pm

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.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,508

Post » Thu May 02, 2013 2:15 pm

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

B
54
S
28
G
18
Posts: 1,520
Reputation: 24,990

Post » Thu May 02, 2013 2:26 pm

Hi,

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

http://www.leiron.be/exttopics3/test/input-form-ajax.capx

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

<?php

/**
* @author Vinson Tan
* @copyright 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
B
5
S
1
Posts: 20
Reputation: 545

Post » Thu May 02, 2013 2:52 pm

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
B
5
S
1
Posts: 20
Reputation: 545

Post » Thu May 02, 2013 6:57 pm

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)
B
54
S
28
G
18
Posts: 1,520
Reputation: 24,990

Post » Tue May 07, 2013 12:45 am

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








B
5
S
1
Posts: 20
Reputation: 545

Post » Tue May 07, 2013 1:14 am

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.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,508

Post » Tue May 07, 2013 5:26 am

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
B
5
S
1
Posts: 20
Reputation: 545


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 0 guests