AJAX and FPCGI
Tyler
tyler.style at gmail.com
Thu May 21 07:13:43 PDT 2009
It is easy to use fpCGI with AJAX. I use it to send JSON formatted data
back and forth all the time.
You can either use a form already on the page, or build one on demand with
javascript.
Make sure you have all the usual fields in the form for fpCGI submission.
>From filePro, you just write out whatever you want to go back (I use JSON,
as I mentioned) and parse it on the client side. I have a JSON javascript
class that does this for me (I could just use eval to instantiate the object
literal, but that's not very robust or secure). (eg) instead of "*responseJson
= eval(XHTP.responseText);* " I use "*responseJson =
JSON.parse(XHTP.responseText);*".
You can grab the JSON class at http://www.json.org/json2.js if you like.
FYI, you can also use PHP to create a direct socket connection to fpCGI and
retrieve the data that way, as well.
(eg)
* $sPost ="";
$aPost =array();
$aPost["Field_ddir"] ="/usr/local/apache/htdocs/";
$aPost["Field_base"] ="ajax";
$aPost["Field_cmd"] ="rreport someTable -fp someProcessing -sr
".rand(1,500)." -n -u -y automaticAJAX";
$aPost["someField"] ="some data";*
* //.....etc....*
*foreach ($aPost as $sFieldName=>$sFieldValue) {
if(!$bFirst) { $sPost .="&"; }
$sPost .=urlencode($sFieldName)."=".urlencode($sFieldValue);
$bFirst =false;
}*
* //you could write this all to the string directly instead of
using an array,
** //**I just find it's clearer code to do it with an array *
*$sHeader ="POST /cgi-bin/fpcgi HTTP/1.1\n"
."Host: $yourServersIp\n"
."Connection: Close\n"
."Content-Type: application/x-www-form-urlencoded\n"
."Content-Length: ".strlen($sPost)
."\n\n$sPost\n";
$oSocket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$bSuccess = socket_connect($oSocket, $yourServersIp, 80);
$iBytesSent =socket_write ($oSocket, $sHeader);
$sResponse = "";
while ($c =socket_read($oSocket, 2056)) { $sResponse .=$c; }
socket_close($oSocket);*
Feel free to hit me up if you have any questions.
--
Tyler Style
http://malthusiansolutions.com
On Thu, May 21, 2009 at 12:30 AM,
<filepro-list-request at lists.celestial.com>wrote:
> Date: Wed, 20 May 2009 05:53:32 -0700
> From: jsola at newportsales.com
> Subject: AJAX and FPCGI
>
> I am trying to use AJAX with FPCGI without success. I have "tricked" FPCGI
> by
> generating external files and combining my code with some PHP code with
> success. However, this have been a solution for simple code. No success
> for
> complex code. Does any one know how to direclty use AJAX with FPCGI.
>
> Att.
> Juan
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.celestial.com/pipermail/filepro-list/attachments/20090521/946b1758/attachment.html
More information about the Filepro-list
mailing list