Ajax Error Name Not Resolved

5.8k views Asked by At

I have a jquery request send at the page load time to which I am getting an error in the console log that says: Failed to load resource: net::ERR_NAME_NOT_RESOLVED

Here is my ajax request:

$(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;
                }
           });
       })();
    });

I am using /22 for the id just for testing purposes. Here is my controller which receives this GET request:

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);            

}
2

There are 2 answers

0
Kevin R. On

Try changing the URL in your get request from:

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

to something like this:

url: "/Employees/Edit/22"

I'm not sure exactly what conditions you are testing your code, but I suspect you are attempting to debug locally, in which case your server may not have that URL configured yet.

EDIT:

Also, depending on how your route configuration is set up, you may need the URL query string defined explicitly, such as:

url: "/Employees/Edit?id=22"
0
Atequer Rahman On

In my case this was hostname issue.

I was using following url which was incorrect.

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

Then replaced by

https://dashboard.revechat.com/ 

Then error resolved.