弃用同步XMLHttpRequest错误消息

时间:2018-04-13 06:16:55

标签: javascript json

所以我在我的控制台app.js:159 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.

中得到了这个

我一直在寻找一种方法将JSON解析为一个url并遇到了这个代码块,这似乎是在抛出错误。

function readJSON(file) {
  const request = new XMLHttpRequest();
  request.open('GET', file, false);
  request.send(null);
  if (request.status == 200)
  return request.responseText;
};

经过一些研究后,我遇到了设置async = true,但没有任何运气。

此外,作为旁注,我的应用程序使用HTML Geolocation并且它不在GitHub页面上工作,但在本地工作正常。有什么想法吗?感谢

1 个答案:

答案 0 :(得分:2)

将false切换为true。语法:XMLHttpRequest.open(method,url,async)

public void ExportToExcel(System.Web.UI.WebControls.GridView controlname, string sheetname)
    {
        HttpContext context = HttpContext.Current;
        context.Response.ClearContent();
        context.Response.Buffer = true;
        context.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", sheetname + ".txt"));
        context.Response.ContentType = "application/text";
       // context.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", sheetname + ".xls"));
       // context.Response.ContentType = "application/ms-excel";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        //Change the Header Row back to white color
        controlname.HeaderRow.Style.Add("background-color", "#FFFFFF");
        //Applying stlye to gridview header cells
        for (int i = 0; i < controlname.HeaderRow.Cells.Count; i++)
        {
            controlname.HeaderRow.Cells[i].Style.Add("background-color", "#507CD1");
        }
        int j = 1;
        //This loop is used to apply stlye to cells based on particular row
        foreach (GridViewRow gvrow in controlname.Rows)
        {
            gvrow.BackColor = Color.White;
            if (j <= controlname.Rows.Count)
            {
                if (j % 2 != 0)
                {
                    for (int k = 0; k < gvrow.Cells.Count; k++)
                    {
                        gvrow.Cells[k].Style.Add("background-color", "#EFF3FB");
                    }
                }
            }
            j++;
        }
        controlname.RenderControl(htw);
        context.Response.Write(sw.ToString());
        context.Response.End();
    }