Thursday, May 2, 2013

How to Get JSON Request Payload?

I'm upgrading a component, select dependent. That actually works, but the code is not completely standardized.


With this configuration (current) I get the data as Form Data. See the screenshot

 var AjaxRequest = function(config_obj,obj){
     var set_obj ={
         type: config_obj.type,
         url: config_obj.url,
         data: obj,
         global: false,
         complete: function(response){
             config_obj.callbacks.complete(response);
         }
     }
     if(config_obj.console_log){
        jQuery('#debug').load(set_obj.url,set_obj.data,function(response, status,xhr){ config_obj.callbacks.complete(xhr); });
     }else{
        jQuery.ajax(set_obj);
     }
 }





With this configuration: The update, I do not get any data in the controller.  See the screenshot

var AjaxRequest = function(config_obj,obj){
    if(config_obj.console_log){
        var set_obj ={
            type: config_obj.type,
            url: config_obj.url,
            contentType: "application/json; charset=UTF-8",
            dataType: 'json',
            data: JSON.stringify(obj),
            global: false,
            complete: function(response){
                $('#debug').html(response.responseText);
                config_obj.callbacks.complete(response);
            }
        }
        $.ajax(set_obj);
    }else{
        var set_obj ={
            type: config_obj.type,
            url: config_obj.url,
            contentType: "application/json; charset=UTF-8",
            dataType: 'json',
            data: JSON.stringify(obj),
            global: false,
            complete: function(response){
                config_obj.callbacks.complete(response);
            }
        }
        $.ajax(set_obj);
    }
}






Saludos Amigos. 



--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: