开发者

What is the difference between Poster post method and jquery post method?

I'm trying to do a post from a mvc3 view and it's not working correctly with my controller, but the same json works fine when I post from Poster

Here is the jquery code

        var lineas = $("#articulosIngresadosTable").getRowData();
        var model = {
            ObraSocialId: $("#idObraSocialTextBox").val(),
            Lineas: lineas
        };

        $.ajax({
            type: 'POST',
            url: '@Url.Action("Nueva", "Factura")',
            data: model,
            success: function (data) { alert(JSON.stringify(data)); },
            dataType: "json"
        });

I double check and the json for the model var is the same that I'm using from Poster

Here is the json:

{"ObraSocialId":"1","Lineas":[{"codigo":"1000","Descripcion":"Articulo 1000","cantidad":"1","importe":"0","descuento":"0","importeDescuento":"0","obrasocial":"开发者_如何学Go","id":"1"},{"codigo":"2000","Descripcion":"Articulo 2000","cantidad":"1","importe":"0","descuento":"0","importeDescuento":"0","obrasocial":"","id":"2"}]}

Thanks in advance!


The problem was the contentType ...

var lineas = $("#articulosIngresadosTable").getRowData();
var model = {
    ObraSocialId: $("#idObraSocialTextBox").val(),
    Lineas: lineas
};

var modelString = JSON.stringify(model);

$.ajax({
    type: 'POST',
    url: '@Url.Action("Nueva", "Factura")',
    data: modelString,
    dataType: "json",
    contentType: "application/json; charset=utf-8",
    success: function (data) { alert(JSON.stringify(data)); }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜