weixin_33739646 2017-04-28 09:06 采纳率: 0%
浏览 13

Ajax发布中的怪异行为

I have this piece of code which works perfectly fine if I set a break point at code behind and let the value become zero and continue to run the rest of the code.

However it will break if i did not set a break point and let it run and the value will become 2 and break.

Does anyone have any idea why? The AJAX code below triggers when the user enters something in the textbox.

function getmachineinfo(serial) {
    $.ajax({
        url: '@Url.Action("actionname", "controller")',
        type: "POST",
        data: { "serial": serial },
        success: function (data) {alert('success')}, error: function (err) {
            alert(err)
        }}
public JsonResult getmachine(string serial)
{

    var machine= service.GetWarrantyDetailsBySerial(serial);     
    result.AccessoriesWs = new List<AccessoriesW>();

    //set break point here and let the result.AccessoriesW to be re declared and set to 0 and it will works.if i don set break point.result.AccessoriesW  will not have enough time to reset to zero.

    return Json(machine, JsonRequestBehavior.AllowGet);
}

Javascript error

A circular reference was detected while serializing an object of type

Result is parent object and AccessoriesW is child object resetting the child object will not get any errors.

Update solution

instead of using

result.AccessoriesWs = new List<AccessoriesW>();

i change it to below and problem solved. i think re declaring constructor is too slow for ajax.

   result.JuraAccessoriesWs.Clear();
  • 写回答

2条回答 默认 最新

  • helloxielan 2017-04-28 10:36
    关注

    Result looks like an instance (not local) variable... It is probably being overridden by other calls in the same controller? Do you do other AJAX calls at the same time?

    It is noting to do with timing, you should either construct the result object locally so it cannot be changed by other code during the action.

    评论

报告相同问题?

悬赏问题

  • ¥15 gojs 点击按钮node的position位置进行改变,再次点击回到原来的位置
  • ¥15 计算决策面并仿真附上结果
  • ¥20 halcon 图像拼接
  • ¥15 webstorm上开发的vue3+vite5+typeScript打包时报错
  • ¥15 vue使用gojs,需求在link中的虚线上添加方向箭头
  • ¥15 CSS通配符清除内外边距为什么可以覆盖默认样式?
  • ¥15 SPSS分类模型实训题步骤
  • ¥100 求ASMedia ASM1184e & ASM1187e 芯片datasheet/规格书
  • ¥15 求解决扩散模型代码问题
  • ¥15 工创大赛太阳能电动车项目零基础要学什么