Ajax summary of js

Ajax js summarized in.
a .ajax role:
1. js is to let the server read the above data.
2. The server reads the above data without refresh, for example: verify the account and password are correct, etc.
(1 ) ajax advantage of:
1. reduce redundancy of service request and response burden caused.
2. no refresh update page, a better user experience.
3. to reduce the burden on the server sketches, saving space and cost of broadband leased.
4. Using asynchronous submit, read and write faster.
(2) ajax drawback:
1.AJAX lot of use of javascript and ajax engine, which depending on the browser's support for browser compatibility considerations at the time of writing.

  1. AJAX is just partial refresh, the back button the page is of no use.
  2. Convective media as well as support for mobile devices is not very good and so on
    . Difference between the two of Get and Post:
    GET way: Common Form of submission: the value submitted after the url; name = value & name = value format?.
    Submit the form example :
    <form Action = "www.baidu.com" Method, = "get" (default is get way)>
    name: <input type = "text" name = "userName"> </br>
    password: <input type = " password "name =" password ">
    <INPUT type =" Submit "value =" submit ">
    </ from>

    the difference:

    1.get mode is to transfer data through the web site, is passed through the POST http the Content.
    Small 2.get capacity, is not suitable for large data transfer, (typically 4k-10k), post embodiment capacity is relatively much larger, generally server up to 2G capacity.
    3. for large files, it will not take the post, take control.
    4.get way poor security, post a bit better, relatively speaking, a bunch of security can only take HTTPS.
    5.get way there are cached, post no cache. get more suited to get the data to the server, post more suited to transfer data to the server,

Three: a write Ajax:
1. Create a ajax object
2. linked to the server
3. The transmission request,
4. receiving the return value,

(1) create a ajax objects
var oAjax = new XMLHttpRequest () // do not support IE6
var = oAjax new new ActiveXObject ( "Microsoft.XMLHTTP"); // IE6 support

 解决兼容性:
        if(window.XMLHttpRequest)
         {
         var  oAjax   = new XMLHttpRequest();
         }
         else
         {
          var  oAjax   = new  ActivexObject("Microsoft.XMLHTTP")
         }

     为什么要用window.XMLHttpRequest作为参数,应为直接XMLHttpRequest做条件,IE6会直接报错,

     但是把XMLHttpRequest作为属性,IE只会报undefined刚好满足我们的条件.

 (2)链接服务器
  oAjax.open('Get',url,true)
  同步:一步步来.
  异步:多件事一起来.
(3)发送请求
  oAjax.send();
(4)接受返回
   oAjax.onreadystatechange = function()
  { 
       //浏览器和服务器进行到哪一步了.
       if(oAjax.readyState==4)//读取完成
        { 

             if(oAjax.status==200)//读取成功
             {
                   fnSuccess(oAjax.responseText)

             }else if( fnfaild)
                  {
                     fnfaild(oAjax.status);

                   }
             }
         } 
  }

readystatus Description
0 (uninitialized) yet call open () Method
1 (loading) calling a send () method, how the transmission request
2 (Loaded) send () method is completed, the entire response has been received
3 ( parsing) response is being parsed
4 (complete) response content analysis is complete, the customer can call a
synchronous request: the request occurs, wait for the server to be finished before continuing the implementation of the current code.

    异步请求:发生请求后,无需等到服务器执行完毕,可以继续执行当前代码。  

Guess you like

Origin blog.51cto.com/1388969/2449378