Reputation: 7053
I have a question about the way I should build my website. What if the user has javascript disabled, then all the client side programming will be disable.
Should I rely on php at first, and then just add the javascript/jquery/ajax just in case.
Also how could I make partial requests, so that one part of the page is posted back while the other part of the page doesnt refresh (for example, navigating through a list of products on the page through a pager , without the whole page refreshing, like a gridview). How to achieve that?
Sorry, if i was confusing
Upvotes: 0
Views: 140
Reputation: 9288
The suggestion I have is to build the site under progressive enhancement.
The key function should be available to user who has javaScript turned off, this means you shouldn't depend on JS for HTML writing, CSS styling and form submission. Also you should always validate form submissions.
You could update part of your html with AJAX. To apply the first principle, You'd better make full post url for every anchor, this will fetch the page from server-side. When js is enabled, you could write AJAX call and diable the default anchor behavior to archive an AJAX page updates.
For example:
1.Provide <a href="specific_page.php">
on your html to ensure no-js user would access the url on your site.
2.When js is enabled, you could select the anchor and use the ajax request instead of the default anchor href.
$('a').click(function () {
$.get('specific_ajax.php', //callback);
return false; //cancel default redirect action
});
You should know how to detect javascript disabled and use <noscript>
as a fallback.
Upvotes: 1
Reputation: 40582
It's been about ten years since any business has asked me to support browsers without js enabled. While it's certainly a valid need in some cases, I wouldn't bother with this sophistication unless you have been given specific instructions or have some insider knowledge of your niche user market (e.g. you are running a bank web site, building gmail, specialty mobile sites, etc).
In most other cases, a simple <noscript>
noting that JavaScript is necessary to enjoy the site's full functionality will suffice.
You will generally want PHP/server-side-technologies to do as much of the work as possible. They will always win against client-side JavaScript for speed and performance. The exception, of course, is application development, where the page should exhibit responsiveness and avoid page reloads for simple content changes. That's where your ajax solutions would come in.
For your "partial requests" question, check out jQuery or another library which provides this functionality. They have excellent tutorials and tools to get you started.
Upvotes: 1
Reputation: 2009
Use <noscript>
tag to handle things when JS is disabled. Wrap your JS with test condition checking if JS is enabled. For partial page you could use iframe
frame
or ajax
.
Typical use of <noscript>
<noscript>
Your browser does not support JS, please <a href="some link">Update your
browser or <a href="noScriptPage.html">go to</a> non JS page which may offer reduced functionality.
</noscript>
<script>
window.location("jsEnabledPage.html");
</script>
So if JS is working the user will be re-directed to the default page else he has options at his disposal.
Upvotes: 1
Reputation: 10258
If your page requires JavaScript to work, then you will need to let the user know that he will need to turn on JavaScript to run your page, otherwise, if you want to support both users who have JavaScript disable and users who do not, you will need to do more work by making all changes done with JavaScript also be done on the server side.
Use AJAX to accomplish that whole changing content of page without refreshing.
Upvotes: 2