Skip to content
Advertisement

Uncaught ReferenceError: data is not defined at HTMLDocument.<anonymous

I am trying to render a Json Response on a html site using AJAX but i keep getting the error:

JavaScript

JsonResponse in Question:

JavaScript

Html file with AJAX and JS:

JavaScript

When i inspect element in my browser, the error points to the data: data being the source of the error. Any idea what i’m doing wrong? I can view the url perfectly with the json response but making it show with ajax is proving a problem

Advertisement

Answer

You are sending data as the body of your request, but first you have to defined the object you are sending to API

JavaScript
Advertisement