1

JSONDATAをrecessframeworkに投稿しているときに問題が発生しました。ブラウザ側から完全に投稿されたJSONデータ。しかし、サーバー側からそれを取得すると、nullになります。理由はわかりません。

SMPLE EXT JSコード:

Ext.Ajax.request({
url : 'http://localhost:8888/index.php' ,
method: 'POST',
jsonData: { dining: {name: 'test',},},
success: function ( result, request ) {
  alert(result.responseText);
},
});

CORE PHPを使用していると、JSONデータを取得できます。しかし、問題はRECESSFRAMEWORKを使用しているときでした。

4

2 に答える 2

3

とうとう深くグーグルして答えを見つけました。ユーザーのHirnhamsterに感謝します、 http: //forums.recessframework.org/ 。

解決

解決策は、実際の問題を見つけるのとは対照的に、かなり簡単です。

1.ステップ:

ファイルDefaultPolicy.class.phpをrecess/recess/frameworkで開きます。メソッドpreprocess(..)に移動します。$ this-> reparameterizeForFormat($ request);という行を追加します。戻る前の最後のコマンドとして。関数は次のようになります。

<?php
    public function preprocess(Request &$request) {
        $this->getHttpMethodFromPost($request);

        $this->forceFormatFromResourceString($request);

        $this->reparameterizeForFormat($request);

        return $request;
    }
?>

2.ステップ

同じファイルで、メソッドforceFormatFromResourceString(...)に移動します。行を変更します$format= substr($ lastPart、$ lastDotPosition + 1); to $ format = strtolower(substr($ lastPart、$ lastDotPosition + 1)); $ request-> format =$format;という行を追加します。以下if($ format!==''){関数は次のようになります。

<?php
    protected function forceFormatFromResourceString(Request &$request) {

        $lastPartIndex = count($request->resourceParts) - 1;
        if($lastPartIndex < 0) return $request;

        $lastPart = $request->resourceParts[$lastPartIndex];

        $lastDotPosition = strrpos($lastPart, Library::dotSeparator);
        if($lastDotPosition !== false) {
            $format = strtolower(substr($lastPart, $lastDotPosition + 1));
            if($format !== '') {
                $request->format = $format;
                $mime = MimeTypes::preferredMimeTypeFor($format);
                if($mime !== false) {
                    $request->accepts->forceFormat($format);
                    $request->setResource(substr($request->resource, 0, strrpos($request->resource, Library::dotSeparator)));
                }
            }
        }

        return $request;
    }
?>

3.ステップ

同じファイルで、メソッドreparameterizeForFormat(...)に移動します。(この関数がすでに存在することに驚いてください:P)。Format :: JSONを「json」に変更し、Format::XMLを「xml」に変更します。関数は次のようになります。

<?php
    protected function reparameterizeForFormat(Request &$request) {

        if($request->format == "json") {
            $method = strtolower($request->method);
            $request->$method = json_decode($request->input, true);
        } else if ($request->format == "xml") {
            // TODO: XML reparameterization in request transformer
        }
        return $request;
    }
?>

4.ステップ

これで完了です。

詳細な解決策について

http://webcache.googleusercontent.com/search?q=cache:http://forums.recessframework.org/topic/189-json-request-doesnt-insert-values-in-v02/

于 2011-12-01T14:18:18.407 に答える
0

試す:

Ext.Ajax.request({
    url : 'http://localhost:8888/index.php' ,
    method: 'POST',
    jsonData: { dining: {name: 'test'} },
    success: function( result, request ) {
        alert(result.responseText);
    }
});

あなたはJavascriptを書いています。}の後の一部の「カンマ」は無効です。

于 2011-11-29T11:00:28.327 に答える