Jump to content
Larry Ullman's Book Forums

Httpservice And Post Problems!


DuPreez
 Share

Recommended Posts

For some reason I cannot POST a value using HTTPService in Flex to my php file.

If I hardcode the value in the php it works 100%, using just the HTTPService with GET.

I need the xml result as dataProvider for a Flex graph and like I said, it works 100% and the graph displays correctly with a hardcoded value in the php.

If I test in the browser like so:

http://localhost/...my_url//myfile.php?itemID=1 I get an undefined index error and obviously if I run my Flex application I get no graph.

If I change the $_POST to $_GET in php and just test in browser I get the correct output.

 

Please help!

 

Here's the php:

<?php header("Content-Type:text/xml");

echo '<data>';

//connection info

define("DATABASE_SERVER", "localhost");

define("DATABASE_USERNAME", "root");

define("DATABASE_PASSWORD", "");

define("DATABASE_NAME", "xx");

 

$dbc = mysqli_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME);

 

$itemID=$_POST['itemID'];

 

$q = "SELECT ID, Name FROM inventory where AreaID = $itemID";

$i=0;

$r = mysqli_query($dbc,$q);

 

while ($row=mysqli_fetch_array($r, MYSQLI_ASSOC)){

$i++;

echo "<node>

<Type>{$row["Designation"]}</Type>

<num>{$i}</num>

</node>

";

}

 

echo '</data>';

?>

 

Here's the Flex:

 

<s:HTTPService id="testData" url="...my_url/myfile.php"

method="GET" resultFormat="e4x" result="xmlHandler(event)"/>

<s:HTTPService id="getChartData" url="...my_url/myfile.php"

method="POST" resultFormat="text" result="getChartData_resultHandler(event)">

<mx:request>

<itemID>{1}</itemID>

</mx:request>

</s:HTTPService>

 

[bindable]

private var testInfo:XMLList;

 

private function xmlHandler(event:ResultEvent):void

{

testInfo = event.result.node;

testChart.dataProvider=testInfo;

}

 

protected function getChartData_resultHandler(event:ResultEvent):void

{

testData.send();

}

Link to comment
Share on other sites

Well, just out of curiosity, why would you use POST here? To me, POST is inappropriate and GET is the correct request method to use. POST is normally used to change server data; GET used to request server data.

Hi, thanks for the reply. It is solved. The problem was I never called/invoked the POST HTTPService in my Flex application. However, I've since dropped the POST HTTPService altogether. I'm only using a GET HTTPService with <s:Request/> where I send the itemID data to the server. Also, in my php file I use $_REQUEST, but I know I can also use $_GET.

Thanks again.

Link to comment
Share on other sites

 Share

×
×
  • Create New...