Welcome Guest, Not a member yet? Register   Sign In
All about Ajax!
#5

[eluser]Jay Turley[/eluser]
My approach is similar. I focus on adding AJAX functionality, rather then baking it in. In the authentication case, I would first build a login page that worked. Once that was successful, I would hijack the form submission using javascript by preventing the default event for the form submission and then submit it using an AJAX request. If I was really on my game, I would also build the interface for the login using javascript by injecting the DOM elements, instead of simply using CSS to hide them and then showing them using javascript.

I've never worried about what Jamie mentions above about checking for the AJAX request server side because I don't use GET requests, only POST except for the case when I expect to receive HTML that will be injected into the DOM (extremely rare). However, I will keep his suggestion in mind for the next time, as I feel it is a good point if you are using a GET. Almost always, though, I return JSON.

I also like to include a token with my AJAX posts so that I can use the same function to return JSON objects or return an HTML view if the token isn't there (i.e. user-submitted).

Edit: although now that I saw the link to Michael Wales' Request library, I will be trying that.


Messages In This Thread
All about Ajax! - by El Forum - 10-03-2008, 07:48 PM
All about Ajax! - by El Forum - 10-03-2008, 08:18 PM
All about Ajax! - by El Forum - 10-03-2008, 08:27 PM
All about Ajax! - by El Forum - 10-04-2008, 02:27 AM
All about Ajax! - by El Forum - 10-04-2008, 02:53 AM
All about Ajax! - by El Forum - 10-04-2008, 04:16 AM
All about Ajax! - by El Forum - 10-07-2008, 02:16 PM
All about Ajax! - by El Forum - 10-07-2008, 06:56 PM



Theme © iAndrew 2016 - Forum software by © MyBB