[SOLVED] Accessing post variables in a blank application

How do I read the POSTed (from another application) variable within a blank application?

I tried both:

  • [posted_var] [I](defined as a POST\GET incoming variable in Application\Global variables)[/I]
  • $_POST['posted_var']
but to no avail.

$_POST[‘posted_var’] is the way if you are calling from an external non sc app.

Are you sure you are receiving the var in POST? Did you looked to headers and make sure?

Giu,

in a grid I have a JS script, triggerd by an onclick event, that POSTs to a blank app (“getp” in the code below) via AJAX:



[B]GRID[/B]
[INDENT]xmlhttp.open("[B]POST[/B]","../getp",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("idacc=21");
[/INDENT]


[B]BLANK[/B]
[INDENT]$id = $[B]_POST[/B]['idacc'];
echo $id;[/INDENT]

And all I get echoed is an “Undefined index: idacc” error.

But if I change the code just to use GET instead:



[B]GRID[/B]
[INDENT]xmlhttp.open("[B]GET[/B]","../getp?idacc=21",true);
xmlhttp.send();[/INDENT]


[B]BLANK[/B]
[INDENT]$id = $[B]_GET[/B]['idacc'];
echo $id;[/INDENT]

it works.

So where’s the error in the POST version??

Because you are not calling correctly. You have to use complete url. I’m sure you are getting a warning on console about this.

xmlhttp.open(“POST”,"…/getp",true);

should be

xmlhttp.open(“POST”,"…/getp/index.php",true) or xmlhttp.open(“POST”,"…/getp/getp.php",true) don’t remember exactly

Giu,

thanks a lot!

Either “…/getp/index.php” or “…/getp/get.php” can be used and the $_POST variable is accessible.