Skip to content
Advertisement

POST net::ERR_NAME_NOT_RESOLVED

I’m trying to create a simple web application form. It requires the user to input their information, and click submit which ideally would hit an api and store the information somewhere like dynamodb.

I have this code

      $.ajax({
        type: 'POST',
        url: 'myAPI',
        contentType: 'application/json',
        data: data,
        success: function(res) {
          $('#form-response').html('<div class="mt-3 alert alert-success" role="alert"><p>Congratulations! You should receive an email with your personalized invitation soon!.</p></div>');
          $('#yobutton').prop('hidden', true);
          $('#yobutton').text('Preferences saved!');
        },
        error: function(jqxhr, status, exception) {
          $('#form-response').html('<div class="mt-3 alert alert-danger" role="alert">An error occurred. Please try again later.</div>');
          $('#yobutton').prop('disabled', false);
        }
      });

which is returning a response error POST net::ERR_NAME_NOT_RESOLVED

For the life of me, I can’t figure out what’s wrong here… It references the jquery.min.js file on this line: s.send(t.hasContent && t.data || null)

Advertisement

Answer

This is a name resolution issue, nothing wrong with your code.

Basically, your computer must “convert” the name of your website to an IP Address it can send packets to.

Name resolution == Hostname -> IP.

This process can be done in multiple ways. Hosts file, local name resolution protocols like llmnr or nbns, and, most famously and probably most relevant, DNS.

If the host that hosts the API doesn’t have a DNS record, As a temporary workaround:

You can add your record to your hosts file

Or maybe input the ip address directly, although that might interfere with HTTP reverse proxies and such.(or theoretically it might change at some point)

If a dns record for it does exist, there’s probably a typo in your ‘myAPI’.

Try running in cmd

nslookup example.com

And then the same but replace the example.com with your hostname. (without the / and everything that follows!)

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement