Mailinglisten-Archive |
Hallo,
vielleicht hat sich von Euch schonmal jemand mit JPSpan beschäftigt...
Ich möchte XUL einsetzten und JPSpan zur Kommunikation JavaScript/PHP verwenden.
Kann mir jemand vermitteln, wie man mit JPSpan ein JavaScript-Array in ein PHP-Array umwandelt ?
Eigentlich hatte ich gehofft JPSpan würde das im Hintergrund automatisch erledigen... oder ist es in JPSpan so
vorgesehen, dass man das Array serialisieren bzw. deserialisieren muss ?
Die JPSpan Doku hilft mir irgendwie nicht weiter.
Hier mal ein Codeschnipsel:
In diesem Beispiel soll die Methode addComponent() über JavaScript aufgerufen werden, die wiederum die gleichnamige php-Methode
aufruft und die Werte des als Parameter übergebenen Array in die DB speichern soll.
Im Moment erhalte ich folgende Fehlermeldung:
"[Server Error] Undefined Index: Description while calling components.addcomponent()"
Andere Datentypen wie Strings oder Integer machen keine Probleme.
Bin für jeden Tipp dankbar :-)
Gruss
Olaf
Beispiel:
/**
* PHP-Klasse
*/
class components {
.....
/**
* save new component into DB
*
* @param array $arr_data
* @since 1.0
* @access public
* @return boolean
*/
function addComponent($arr_data) {
....
// save data into DB
$this->putArray($arr_data);
....
}
....
}
/**
* JPSpan-Client
*/
function addComponent() {
// Create the client object, passing the async
// handler. Note lower case!
var c = new components(ResponseHandler);
var arr_data = new Array;
arr_data["foo"] = "foo";
arr_data["bar"] = "bar";
// Call the remote method (method lower case!)
c.addcomponent(arr_data);
}
// A handler is required to accept the response
// of asychronous calls...
var ResponseHandler = {
// Function must have same name as remote method
addcomponent: function(result) {
alert(result);
}
}
// call function
addComponent();
/**
* JPSpan-Server
*/
// Create the PostOffice server
$S = & new JPSpan_Server_PostOffice();
// Register your class with it...
$S->RequestEncoding = 'php';
$S->addHandler(new components($dsn));
// This allows the JavaScript to be seen by
// just adding ?client to the end of the
// server's URL
if (isset($_SERVER['QUERY_STRING']) &&
strcasecmp($_SERVER['QUERY_STRING'], 'client')==0) {
// Compress the output Javascript (e.g. strip whitespace)
define('JPSPAN_INCLUDE_COMPRESS',TRUE);
// Display the Javascript client
$S->displayClient();
} else {
// This is where the real serving happens...
// Include error handler
// PHP errors, warnings and notices serialized to JS
require_once JPSPAN . 'ErrorHandler.php';
// Start serving requests...
$S->serve();
}
php::bar PHP Wiki - Listenarchive