Poster post方法和jquery post方法有什么区别?

时间:2011-07-22 15:20:07

标签: jquery ajax poster

我正在尝试从mvc3视图发帖并且它与我的控制器无法正常工作,但是当我从海报发布时,同样的json工作正常

这是jquery代码

        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"
        });

我仔细检查,模型var的json与我在Poster

中使用的相同

这是json:

{"ObraSocialId":"1","Lineas":[{"codigo":"1000","Descripcion":"Articulo 1000","cantidad":"1","importe":"0","descuento":"0","importeDescuento":"0","obrasocial":"","id":"1"},{"codigo":"2000","Descripcion":"Articulo 2000","cantidad":"1","importe":"0","descuento":"0","importeDescuento":"0","obrasocial":"","id":"2"}]}

提前致谢!

1 个答案:

答案 0 :(得分:0)

问题是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)); }
});