1

js code to define an ajax call:

function InitDataServices() 
{    
    amplify.request.decoders.myDecoder =
    function (data, status, xhr, success, error) 
    {
      if (status === "success")           {
         success(data);
      } else if (status === "fail" || status === "error") {
        error(message, status);
    } else {
        error(message, "fatal");
    }
};

amplify.request.define("Emision_FiltrarSeguros", "ajax", {
    url: "http://localhost:63721/api/emision/filtrar",
    type: "POST",
    dataType: "json",
    decoder: "myDecoder"
});
}

Then the code to make the actual ajax call is:

function Emision_FiltrarSeguros(requestData,okFunction, failFunction) 
{
     amplify.request({
    resourceId: "Emision_FiltrarSeguros",
    contentType: "application/json",
    data: JSON.stringify(requestData),
    success: function (data) {
        okFunction(data);
    },
    error: function (message, level) {
        failFunction(message,level);
    }
});
};

And finally this code in the page to make the call:

function FiltrarSeguros()
    {   
        this.request = {Ramo:-1, 
                        NroSocio: 107701,
                        NroSeguro:-1,
                        NroEndoso:-1,
                        Vigentes:0,
                        Patente:"" };
        Emision_FiltrarSeguros(request,okFiltrarSeguros, failFiltrarSeguros);
    }

The controller code is this:

public List<FiltroSeguroResponse> Filtrar(FiltroSeguroRequest request)
    {
        return DLL.Service.EmisionService.FiltrarSeguros(request, "jdh");
    }

The problem is that the data that i POST from the page never get mapped to the request (of type FiltroSeguroRequest, whose properties are the same as the object literal I build in the ajax call) parameter. What is wrong??? Thanks.

2
  • Could you share how your raw request(from Fiddler probably) looks like? Commented Nov 28, 2012 at 18:19
  • did you manage to get this working as i am also facing the same issue, Commented Mar 14, 2013 at 14:21

1 Answer 1

0

Add the content-type to where you define your amplify request like this:

amplify.request.define("Emision_FiltrarSeguros", "ajax", {
    url: "http://localhost:63721/api/emision/filtrar",
    type: "POST",
    dataType: "json",
    decoder: "myDecoder",
    contentType: 'application/json; charset=utf-8',
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.