This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

drewloomer
drewloomer

I am having a bizarre issue with returning JSON data. This only happens on my dev server and not with my local Vagrant machine.

When using Response::json to return JSON data from a controller, I am seeing X_OCTOBER_ASSETS returned in addition to the JSON response. Here is my code:

public function onSaveQuote($recordId = null)
    {
        try {

            $model = $this->formFindModelObject($recordId);
            $id = Request::get('id');

            if (!$id) {
                $quote = new WorkQuote();
                $quote->work_item_id = $recordId;
                $model->quotes->add($quote);
            }
            else {
                $quote = $model->quotes->find($id);
            }

            $quote->content = Request::get('content');
            $quote->attribution = Request::get('attribution');
            $quote->save();

            Response::json($quote, 200)->send();
        }
        catch (Exception $ex) {
            Response::json($ex->getMessage(), 400)->send();
        }
    }

The desired response looks like this: {"work_item_id":"5","content":"sdf","attribution":"","id":"18"}

On my server I am seeing this: {"work_item_id":"5","content":"sdf","attribution":"","id":"18"}{"X_OCTOBER_ASSETS":{"js":["http:\/\/dpop.drewloomer.com\/modules\/cms\/widgets\/mediamanager\/assets\/js\/mediamanager-browser-min.js?v318"],"css":["http:\/\/dpop.drewloomer.com\/modules\/cms\/widgets\/mediamanager\/assets\/css\/mediamanager.css?v318"],"rss":[]}}

Has anyone else run into this issue? I can't fathom why they are behaving differently; the Composer packages seem to be the same.

Thanks, Drew

drewloomer
drewloomer

The plot thickens. I'm seeing duplicated responses from the server in other instances. Does anyone know why multiple responses are being joined together?

DMeganoski
DMeganoski

This is probably because you are not actually returning anything in your function, and October is 'not aware' that you have sent a response already, so it makes it's own. try


return Response::json('...')->send();

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.