Probably just not thinking about this the correct way, but can you use
AJAX to call A4D code?
Ajax is an http request like any other as far as Active4D is
concerned. Like Brad said, the big difference is that you are
returning only part of a page. So far I have always returned HTML,
not XML.
If you are using the prototype library to do your Ajax calls, do
something like this in the root-level fbx_layouts.a4d:
// Ajax requests get no layout
if (request info{"X-Requested-With"} # "XMLHttpRequest")
$fusebox{"layoutDir"} := "layouts"
$fusebox{"layoutFile"} := "lay_main.a4d"
end if
You don't want your full page layout coming back with a partial page.
The other issue to deal with is timeouts. If a session times out when
an Ajax call is made, you need to handle that. I do this in the
fbx_settings.a4d within my session-only circuit:
if (session{"user.id"} = "")
if (request info{"X-Requested-With"} = "XMLHttpRequest")
redirect(fusebox.makeURL("login.ajaxTimeout"))
else
redirect(fusebox.makeURL("login.timeout"))
end if
end if
The login.ajaxTimeout fuseaction includes this display fuse:
<%$fusebox{"nestLayouts"} := false%>###timeout###
Turning nestLayouts off prevents layouts from being used, since you
only want the text ###timeout### to be returned, which you look for
in the completion handler within your javascript:
onComplete: function(request)
{
if (request.responseText)
{
if (request.responseText.substr(0, "###timeout###".length) ==
"###timeout###")
{
window.location = this.timeoutUrl;
}
else
{
// success
}
}
else
{
// failure
}
}
Regards,
Aparajita
www.aparajitaworld.com
"If you dare to fail, you are bound to succeed."
- Sri Chinmoy | www.srichinmoylibrary.com
_______________________________________________
Active4D-dev mailing list
[email protected]
http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev
Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/