knockout.viewmodel icon indicating copy to clipboard operation
knockout.viewmodel copied to clipboard

custom-unmapped model cannot be send with ajax-request

Open fgieseke opened this issue 11 years ago • 0 comments

Given: A custom mapping option to map and unmap a model. Running this code var model = ko.viewmodel.toModel(vm); $.ajax({ type: "POST", url: "/someService", dataType: "json", data: model })

produces an exception because jquery (2.1.1) runs into this

    // Convert data if not already a string
    if ( s.data && s.processData && typeof s.data !== "string" ) {
        s.data = jQuery.param( s.data, s.traditional );
    }

and in the end executes the custom mapping function without passing an object to the map-function. The reason for this is that the model still has 2 functions defined: ___$mapCustom and ___$unmapCustom

Workaround var model = ko.viewmodel.toModel(vm); delete model._$mapCustom; // cleanup model delete model._$unmapCustom; // cleanup model $.ajax({ type: "POST", url: "/someService", dataType: "json", data: model })

fgieseke avatar Dec 29 '14 18:12 fgieseke