How do I post data using AJAX?

Get help using Construct 2

Post » Wed May 15, 2013 12:43 pm

Where do you capture this error messages?
B
7
S
1
G
1
Posts: 32
Reputation: 1,016

Post » Thu May 16, 2013 9:44 am

@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.
B
96
S
25
G
20
Posts: 3,055
Reputation: 22,646

Post » Thu May 16, 2013 2:03 pm

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.Prox2013-05-16 14:03:48
B
7
S
1
G
1
Posts: 32
Reputation: 1,016

Post » Fri Aug 23, 2013 3:19 pm

@Prox would it be possible to post (upload) and image/screenshot from the guy this way?
B
5
Posts: 48
Reputation: 346

Post » Sat Oct 11, 2014 9:38 am

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
<?php
/*db connection menthod*/
header("Access-Control-Allow-Origin: *");
$query = mysql_query("insert into score (`score`)values('".$_POST['score']."')");

if($query)
echo "done";
else
echo "notdone";
?>

/*getting error of */

Notice: Undefined index: score in
You do not have the required permissions to view the files attached to this post.
B
3
Posts: 9
Reputation: 195

Post » Sat Oct 11, 2014 9:43 am

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.
B
11
S
2
G
1
Posts: 68
Reputation: 777

Post » Sat Oct 11, 2014 9:45 am

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.

Thanks
B
3
Posts: 9
Reputation: 195

Post » Sat Oct 11, 2014 12:17 pm

Apologies., I did also explain that it doesnt solve that issue and that im at work so couldnt do that part with the capx...
B
11
S
2
G
1
Posts: 68
Reputation: 777

Previous

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 23 guests