Any output during the script execution will be included in the response body (actually, is the response body), and you can always see the full response in the network panel of the browser dev tools (which also provide some nice features such as appropriately formatting the data, or even rendering HTML). Of course, doing so will likely lead to invalid data your JS won't understand... e.g. if you expect a JSON response,
var_dump()ing random values will give you something like
Debug message: the eggs are overcooking!
"data": "This should be the actual response"
JSON.parse() will throw an error. So in most cases you'll want to log your debug info to a file, which you can monitor with
tail -f like @Andres_Vaquero suggested... other than that, you might have a look at xdebug for some more sophisticated debugging with breakpoints and all.