How should an AJAX application behave when Javascript is disabled - a common practice?

Im in the process of developing a fairly simple web application, i.e. basically, so I could learn jQuery / ajax / php in a way (and have some fun). I want to make it as accessible as possible for users, so it should work with Javascript disabled, check for AAA and all that. With JS-disabled people, of course, it would be without all the bells and whistles, but nevertheless, this work should have been done.

I would like to use Ajax well, but I do not understand how to handle it when JS is disabled.

So, let's say that JS is turned on, the user submits the form, clicks the submit button and through ajax, the data is sent to register.php (register.php is specified in the action attribute). register.php returns data, and jQuery displays the corresponding message. All without reloading the page.

Now, if JS is disabled, submitting the form in register.php will not do much good.

As I understand it, the solution would be to create one PHP script for JS enabled, another for JS disabled. Thus, by default, the form will have an action attribute with nonjs_register.php, and if JS is enabled, it will force the form to submit to js_register.php, and not by default nonjs_register.php. I can imagine that it would be rather tedious to create two pages of scripts for each user interaction, but this is the only way I can think of at the moment.

I hope this all makes sense, but please let me know if my explanations are not entirely clear. Now, if someone could explain to me what is common practice to solve this problem, which would be great.

+5
source share
6

Hijax, AJAX .

+2

, , - javascript, . URL:

HTML

<form id="AjaxForm" action="/nonJS_register.php" method="POST">
   <!-- form input elements -->
</form>

JS

document.getElementById("AjaxForm").onsubmit = function ()
{
     //- do ajax posting...
     ajaxPostForm();

     //- Cancel the default action of the form
     event.preventDefault();
     return false;
}

ajax nonJS_register , script, HTML.

+2

:

  • , JS .
  • JS - . ..
  • AJAX (, HTML/PHP JS , JS , AJAX false, )
+2

, , , , AJAX. , , JavaScript. JavaScript / JavaScript.

+1

AJAX , Javascript.

, , .

Javascript , AJAX . postbacks "click" , (a.k.a. AJAX).

, , Javascript, , Javascript.

+1

, register.php HTTP-: Accept , , :

  • : application/xhtml + xml, text/html, multipart/mixed, */*

    HTML- .

  • , - ,

    : /json, application/javascript, text/javascript

    JSON ( ) XML, mime, , .

Javascript- onsubmit , , ( Accept, ). javascript , , PHP -.

+1

All Articles