Jump to content

Ajax when Javascript is disabled!


rameshfaj

Recommended Posts

What happens to the Ajax coded application if the javascript is disabled?I have used Ajax in some of my PHP pages,what will happen if the javascript is disabled by the client?Will it be useless at all or is there any other technique to make it functional?

Link to comment
Share on other sites

It becomes useless. Which is why sites should always be programmed in entirety without javascript and then have javascript applied overtop after the fact.

 

For example, if you have a forum where posts are made using javascript, the button should work and bring the user to a new post page if javascript is turned off.

Link to comment
Share on other sites

thanks everybody,but is there any alternative to check if the browser has disabled the javascript and then activate some other pages that donot use javascript?Or not to use the Ajax at all?I am little bit confused.

I think it wont be good to inform user to enable javascript else our application wont work,I mean to say we need to get the way without informing the user that we are going to do our work in some other manner.

Link to comment
Share on other sites

Yes, there are tests to see if JavaScript is enabled. One way is to have JS code to set a cookie, then check in PHP if it is set.

 

You can then use that to determine different logic to follow based upon JS being enabled or not. For example, if you have "nested" select boxes where the value of one determines the values in the other (e.g. state and city), then you would have to allow the user to select the state and submit the value to get the list of cities as opposed to using AJAX to populate the list on the fly. Each implementation will require a different approach.

Link to comment
Share on other sites

I personally build my applications 100% without ajax first. They work entirely in PHP and do everything then need to do. Then I add the javascript over top of the pages using 'unobtrusive javascript' (google it, its great stuff). This way if a person accesses my page with javascript turned off, they still see an entirely functioning page. Actually, the way I have it developed, they can't even tell that there is ajax or javascript that is not being loaded.

 

If you wanted to, you could start out with a div somewhere visible on the page that contains some text telling the user that the page is designed to work with javascript, and while it will still work without javascript, it works better with javascript turned on. Then you can set javascript to set that div to display:none; when the window loads. This way the warning will be visible to anyone who has javascript turned off, but will disappear when someone has it turned on.

 

I use this technique lots on my pages. For example I often have buttons that only work with javascript turned on. In my xhtml/css, I set the buttons to display:none, and then use javascript to change that to display:block when the window loads. This way, if a person accesses the page without javascript on, they cannot even see the buttons, so there arent unusable buttons on the page. And if they have javascript turned on, the buttons become visible and can be used by the user.

 

I also use it on pages where I have collapsible divs. The divs aren't visible until a plus button or something is pushed. I initially make the divs visible in the xhtml/css, but then I set them to collapse using javascript. This way it looks nice when a user has javascript turned on, but still works entirely fine with javascript turned off. And the plus button is not even visible if the person has javascript turned off.

 

This is why it is so important to do javascript last. Build your pages in php/xhtml/css. When you are done, then its time to add the javascript.

 

Javascript is a great language. It adds function and makes pages easier to work with for the user. But its one big drawback is that its not dependable. You can never really know if a user has javascript turned on or not, so you have to plan for them to not have it turned on, and then make it work if they do have it turned on.

Link to comment
Share on other sites

thank you all for your kind response.Its really sad that some browsers dont support the javascript or some  people misuse it to generate some injective scripts like worms,virus etc.

yea it is good to have the site independent of the javascript,it will be better to make the site functional without javascript though we need to work a lot.

once again,Thank you very much.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.