【发布时间】: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