Debugging ajax    AJAX

Debugging AJAX can sometimes be a bit tricky. Within ajaxed we try to give you as most debugging facilities as possible. This article shows you all of them (you should know how to deal with ajaxed already).

JavaScript debugging

In most cases you are dealing with an AjaxedPage instance when working with AJAX. In that case you can set its debug property to true to get more information about the ajax life cycle. Thats especially useful when you experience problems during the ajaxed.callback call.

It will give you information about which action is being called (being sent to the server side callback()), what parameters are being sent to it, which URL is being requested and what the response looks like. All debug information will pop up in JavaScript alert boxes.

<!--#include virtual="/ajaxed/ajaxed.asp"-->
<%
set page = new AjaxedPage
with
  .debug = true
  .draw()
end with

sub callback(a)
  if a = "do" then page.return "done"
end sub

sub main() %>
  
  <button type="button" onclick="ajaxed.callback('do', function(r) { alert(r)})">
    clik me for debug info
  </button>

<% end sub %>
Run this code — debug.asp


Debugging with Logger

Using our built in Logger helps you to debug every piece of your code. Hook up the Logger as describe in Debugging & Logging and log messages within you callback() routine.


<%
sub callback(a)
  lib.logger.debug "Action: " & a
  if a = "some" then
    lib.logger.debug "Went here"
  else
    lib.logger.error "Should not be here"
  end if
end sub
%>


TIP: If you take a look at your logfiles you will recognize detailed tracing information about all the ajax calls. We highly recommended to set up logging.

Basic Pop Up messages

Sometimes you just want to do a simple str.write() within the callback() but its not possible as its never written back directly into the browser.

In that case you can use the lib.error() or lib.throwError() method to alert some debug details. The first one stops the response, flushes it and write out the error message (useful for debugging or user friendly errors). The latter throws a real runtime error which can also be caught by error handlers.


<%
sub callback(a)
  if a = "some" then
    a = 1 + 2
    'can be useful for debugging
    lib.error("a = " & a)
  else
    lib.throwError("Invalid call.")
  end if
end sub
%>

The good thing about both methods is that they cause our ajaxed.callback to fail and thus the JavaScript calback function is not called. Thats good cause it might produce errors as the callback failed already.

Posted in AJAX 3215 days ago

Version 2.1.1 Released1557 days ago