weixin_33725126 2015-07-21 15:43 采纳率: 0%
浏览 22

Json未发送数据

I am having strange problem with Json.

I am making an ajax call to a Controller method which is taking a string as a input and sends back a List of my class.

Basically, I am making the json call on change of dropdown menu, for loading the corresponding fields of another dropdown menu.

In dropdown menu 1, i have 2 options and a placeholder("Select").

The strange thing is that, when i am selecting the 2 option, it is adding the data to the dropdown menu 2. But if i select the option 1, Then it is not getting data in json call, hence not adding anything to the dropdown menu 2, although my controller function is returning the data in json.

My json call is below:

function changeTable() {
            var index = 0;
            var info = { majoraccountvalue: document.getElementById("expancesMajorAccount").value };
            var dropdowm = $("#expancesMinorAccountName");
            jQuery.ajax({
                type: "POST",
                url: "@Url.Action("GetData")",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(info),
                success: function (data) {
                    debugger;
                    var arr = data.MinorAccountHeads;
                    dropdowm.empty()
                    alert(data);

                    for (index = 0; index < arr.length; index++) {
                        dropdowm.append($('<option></option>').val(arr[index].ID).html(arr[index].Name));
                    }
                },
                failure: function (errMsg) {
                    alert(errMsg);
                }
            });
        }

And my controller method is:

public JsonResult GetData(long majoraccountvalue)
     {
         Myclass model = new myclass();
         model.FillData(majoraccountvalue);
         return Json(new { model.MinorAccountHeads });
     }

My controller function is returning data in both the cases. When i select the option 1 as well as if i select option 2.

Thanks

  • 写回答

2条回答 默认 最新

  • weixin_33704591 2015-07-22 04:52
    关注
    1. Try using cache:false in ajax parameters.
    2. Failure - isn't correct. You need using 'error'. May be the first request you get an error...
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办