【问题标题】:Ajax Error Name Not ResolvedAjax 错误名称未解析
【发布时间】:2015-06-18 14:23:46
【问题描述】:

我在页面加载时发送了一个 jquery 请求,我在控制台日志中收到一条错误消息: 加载资源失败:net::ERR_NAME_NOT_RESOLVED

这是我的 ajax 请求:

$(document).ready(function() {
        (function(){
            console.log("ran");
            $.ajax({
                type: "GET",
                url: "https://clas-test4.uconn.edu/Employees/Edit/22",
                dataType: "json",
                success: function (data) {
                    console.log("Success: " + data);
                    empData = data;
                }
           });
       })();
    });

我使用 /22 作为 id 仅用于测试目的。这是接收此 GET 请求的控制器:

public ActionResult Edit(int? id)
{
    if (id == null)
    {
        return Json("Error: Id does not exist", JsonRequestBehavior.AllowGet);
    }

    employee employee = db.employees.Find(id);

    if (employee == null)
    {
        return Json("Error: employee does not exist", JsonRequestBehavior.AllowGet);
    }

    return Json(employee, JsonRequestBehavior.AllowGet);            

}

【问题讨论】:

  • “名称未解析”听起来浏览器无法解析 AJAX 请求的主机名。你能连接到那个主机名吗?

标签: c# jquery asp.net-mvc asp.net-ajax


【解决方案1】:

尝试更改获取请求中的 URL:

url: "https://clas-test4.uconn.edu/Employees/Edit/22"

到这样的事情:

url: "/Employees/Edit/22"

我不确定您测试代码的确切条件,但我怀疑您尝试在本地调试,在这种情况下,您的服务器可能尚未配置该 URL。

编辑:

另外,根据您的路由配置的设置方式,您可能需要明确定义的 URL 查询字符串,例如:

url: "/Employees/Edit?id=22"

【讨论】:

    【解决方案2】:

    在我的情况下,这是主机名问题。

    我使用的以下网址不正确。

    https://www.dashboard.revechat.com/
    

    然后替换为

    https://dashboard.revechat.com/ 
    

    然后错误解决。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-17
      • 2019-06-21
      • 1970-01-01
      相关资源
      最近更新 更多