【问题标题】:What is the difference between Poster post method and jquery post method?Poster post 方法和 jquery post 方法有什么区别?
【发布时间】:2011-10-11 03:43:38
【问题描述】:

我正在尝试从 mvc3 视图发帖,但我的控制器无法正常工作,但当我从 Poster 发帖时,相同的 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"
        });

我仔细检查,模型变量的 json 与我在海报中使用的相同

这是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"}]}

提前致谢!

【问题讨论】:

    标签: jquery ajax poster


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2011-05-07
      • 2013-08-26
      • 2020-02-02
      • 2023-01-24
      • 1970-01-01
      • 1970-01-01
      • 2015-12-16
      • 2014-02-05
      • 2013-10-06
      相关资源
      最近更新 更多