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 三菱伺服电机按启动按钮有使能但不动作
  • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号