class.php、functions.js、interface.php の3 つのファイルがあります。
class.phpは、メソッドと属性を定義する oophp ファイルです。
interface.phpは、class.php のオブジェクトのメソッドを使用する関数を定義します
オブジェクトは index.php で定義され、セッションに保存されます。
functions.js を使用して、interface.php で POST-Calls (jQuery) を実行します。
私の問題:
functions.js の $.post で interface.php の init() 関数が呼び出されます。 init() 関数は、class.php のオブジェクトの test() 関数の戻り値を返します。
編集:
functions.js
$(document).ready(function() {
init();
});
function init() {
$.ajax({
type: 'POST',
url: 'interface.php',
data: {f: 'init'},
success: function(data) {alert(data);}
});
}
interface.php:
<?php
require_once('class.php');
session_start();
if(isset($_REQUEST['f'])) {
$func = $_REQUEST['f'];
$func();
}
function init() {
$obj = $_SESSION['object'];
echo $obj->test(); // test() returns an array like array('test1', 'test2')
}
?>
test() が返すものは何でも、Firefox では空の alert() が返されます。Chromeで動作します!あなたは問題を知っていますか?