1

I am facing trouble while posting JSON DATA to recess framework. The JSON data posted perfect from the browser end. But when i get that from the server end it becomes null. I don't know the reason.

SMPLE EXT JS CODE:

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

I can get the JSON data when i am using CORE PHP. But the issue was when im with RECESS FRAMEWORK.

Naveenkumar
  • 77
  • 3
  • 10

2 Answers2

3

Finally I found the answer after deep googling. Thanks to Hirnhamster the user, http://forums.recessframework.org/.

Solution

The solution is - in contrast to finding the real problem - rather easy:

1. Step:

Open the file DefaultPolicy.class.php in recess/recess/framework. Go to method preprocess(..). Add the line $this->reparameterizeForFormat($request); as last command before returning. The function should now look like this:

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

        $this->forceFormatFromResourceString($request);

        $this->reparameterizeForFormat($request);

        return $request;
    }
?>

2. Step

In the same file, go to method forceFormatFromResourceString(...). Change the line $format = substr($lastPart, $lastDotPosition + 1); to $format = strtolower(substr($lastPart, $lastDotPosition + 1)); Add the line $request->format = $format; below if($format !== '') { The function should now look like this:

<?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. Step

In the same file, go to method reparameterizeForFormat(...). (Be astonished that this function already exists :P). Change Format::JSON to "json" and Format::XML to "xml" The function should now look like this:

<?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. Step

You are done.

For Detailed Solution:

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

Naveenkumar
  • 77
  • 3
  • 10
0

Try:

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

You're writing Javascript. Some "commas" after } aren't valid.

riyuk
  • 174
  • 1
  • 6
  • Hey rijuk, Thanks for your suggestion. But the changes too cause the same issue. – Naveenkumar Nov 29 '11 at 11:31
  • For Solution: http://webcache.googleusercontent.com/search?q=cache:http://forums.recessframework.org/topic/189-json-request-doesnt-insert-values-in-v02/ – Naveenkumar Nov 29 '11 at 12:14