jejacks0n/mercury

Data not recieved by server.

Opened this issue · 0 comments

Hello everyone,

First of all I know this is for rails but I like the editor so much that I just need to have it for PHP.
So for about 3 days I have been in a total war to get the data send to the edit/save page.
Finally got it working how it is supossed to work.
Now I am also debugging using the console so I can see what happans.

Here are the results when I am saving :

POST http://localhost/se/backend/bewerk [HTTP/1.1 200 OK 2215ms]
"{"pages/home":{"type":"full","data":{},"value":"<p>This is the homepage.</p>","snippets":{}}}" home:68

So I know it is being send.
Now I am trying to catch the json with php like this :

    public function bewerk() {
        $submit_data = $_POST;
        $json = json_decode($submit_data, true);

        if(isset($json)){
            $data = json_decode($json);
            $this->model->save_data($data);
        } else {
            //$data = var_dump(get_object_vars("object Object"));
            echo json_encode(array("value" => "$json"));
        }
    }

So I am also requesting to get the post that is just sended.

Mercury.PageEditor.prototype.save = function() {
var url = "{{ constant('BASE_URL') }}backend/bewerk";
var data = this.serialize();
Mercury.log('saving', data);
if(this.options.saveStyle != 'form') data = jQuery.toJSON(data);
var method = (this.options.saveMethod == 'PUT') ? 'PUT' : 'POST';
jQuery.ajax(url, {
type: method,
dataType: this.options.saveDataType || 'json',
data: {_method: method, content: data},
success: function() {
Mercury.changes = false;
Mercury.trigger('saved');
console.log(data);
  $.get(url, function( data ) {
  console.log( "Load was performed."+data );
  });
},
error: function() {
alert("Mercury was unable to save to url:\n"+url);
}
});
};

----- 
Result in console : 
GET http://localhost/se/backend/bewerk [HTTP/1.1 200 OK 2280ms]
"Load was performed.{"value":""}" home:70

I hope somebody can help me.
The reason why I want this to work is because I want to use it in al my projects.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.