Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
DuPreez

Httpservice And Post Problems!

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();

}

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...