Welcome Guest, Not a member yet? Register   Sign In
AJAX or NO AJAX?
#2

[eluser]kgill[/eluser]
[quote author="Deep Arora" date="1263606926"]I just started with the AJAX stuff and have a dumb question..

I understand that we can check in CI if the request is ajax or not:

Code:
if (IS_AJAX) {

But doesn't this make our overall code lengthy? I mean, now we need to write the same code twice..one the ajax version, and one without ajax?
[/quote]
No, never re-write the same logic, that's a waste. Instead move the common code into a separate function(s) and have each call that so that only the code that is specific to each request needs to be written.

Quote:Second - if javascript is disabled in the broswer, how will we determine if ajax is failed. That is, how do we auto route to without-ajax part of code in case ajax fails for some reason? Because in my view, I will simply call the javascript function. Once it is called, its ajax call..so do i need to determine it in VIEW itself?

If javascript is disabled, AJAX isn't even going to happen there's no need to determine if it failed. So you have to decide do you want the app to always work or do you want to tell the user if you don't want to use JS then you can't use the app. If it's the former, you need to code your apps for graceful degradation, make sure everything works with JS turned off first then you start capturing events in the browser to trigger your AJAX stuff. If it's the latter a simple no script tag stating the app won't work without JS covers that.


Messages In This Thread
AJAX or NO AJAX? - by El Forum - 01-15-2010, 01:55 PM
AJAX or NO AJAX? - by El Forum - 01-15-2010, 03:15 PM
AJAX or NO AJAX? - by El Forum - 01-15-2010, 03:23 PM
AJAX or NO AJAX? - by El Forum - 01-15-2010, 03:23 PM
AJAX or NO AJAX? - by El Forum - 01-15-2010, 06:12 PM
AJAX or NO AJAX? - by El Forum - 01-15-2010, 06:40 PM
AJAX or NO AJAX? - by El Forum - 01-15-2010, 06:59 PM
AJAX or NO AJAX? - by El Forum - 01-15-2010, 07:12 PM
AJAX or NO AJAX? - by El Forum - 02-10-2010, 11:59 AM
AJAX or NO AJAX? - by El Forum - 02-11-2010, 06:32 PM



Theme © iAndrew 2016 - Forum software by © MyBB