79769068

Date: 2025-09-19 02:52:56
Score: 0.5
Natty:
Report link

What “Failed to fetch” Means

That error does not come from your API code directly.
It usualy means browser stopped the request before it could give jQuery response.

Common causes:

  1. CORS issue → API not allowing requets from your domain.

  2. Network/URL issue → wrong URL, DNS issue, HTTPS mismatch (calling HTTP from HTTPS).

  3. Response format issue → API returned invalid or unexpected content (like plain content('0')) instead of JSON/XML/text that your jQuery expects.

Why might you still see TypeError: Failed to fetch?

  1. Not really hitting your handler

    • If your page is /ControllName/ForgotPassword, then the URL should be:

      /ControllName/ForgotPassword?handler=ForgotPwd&UserName=xxx
      
      

      not just /?handler=....

  2. CORS or HTTPS mismatch

    • If you’re calling this from another domain (or from HTTPS → HTTP), the browser blocks it.

    • In that case, “Failed to fetch” shows before it even gets the response.

    • You can check program.cs file both configuration.

  3. Exception on server

    • If the server throws inside OnGetForgotPwdAsync, the API may return 500 Internal Server Error.

    • Check Network tab in DevTools (F12) → what’s the actual status code?

Fix Suggestions

1. Correct the URL

If your page is a Razor Page at /ForgotPwd, then:

const resp = await fetch(`/ForgotPwd?handler=ForgotPwd&UserName=${usrname}`);

2. Make sure to return text properly

If you always want text back:

return Content("0", "text/plain");

3. Debug in DevTools

Most likely issue = wrong URL (/?handler=...) or server error.

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): What
  • Low reputation (1):
Posted by: smit patel