JavaScript closures and ajax

Concept closure package:

  • A function to access the local variables of the function having the function that is nested function;
  • Effect: the closure is not released due to the variable in the memory, can be used to store variables;
  • Since the closure of the occupied memory is not released, so it should avoid abuse closure

Closure Reference URL: https: //www.jianshu.com/p/a2dd93e2d195

ajax:

  • Asynchronous javascript and XML;
  • Used to implement the partial update web content;
  • Front and back office tools make data interaction;

ajax use:

Reference URL: https: //www.jianshu.com/p/5c324a7726d3

① achieve get data acquisition
        1- create request object
        var Ajax = new new the XMLHttpRequest ();
        2- setting request parameters 
       ajax.open (method, url, whether asynchronous); 
       ajax.open ( ? 'Get', 'data.txt COUNT = 10 ', to true );
        3- transmission request 
       ajax.send ();
        4- listening state change request
            @ ajax.readyState request status code   
           @ 0: creating a request object 
           @ 1: Open call 
           @ 2: call of the send 
           // 3: return to the part of 
           // 4: complete response is complete 

           // ajax.status response status code 
           // 1XX: response is being processed 
           // 2XX: 200 succeeded in finding
           // 3XX: are successfully found, or may be redirected to the cache fetch 
           // 4XX: 404 not found 
           // 5XX: 502 Server Error 

       ajax.onreadystatechange = function () {
            IF (ajax.readystate. 4 && == Ajax. == 200 is Status ) { 
               ajax.responseText; // response data 
           } 
       }  - POST submit data
       var Ajax = new new the XMLHttpRequest (); 
      ajax.open ( 'POST', 'User / Login' );
      // POST method requires setting request header 
      ajax.setRequestHeader ( 'the Content-type', 'file application / X-WWW-form-urlencoded' );
     //Data transmitted on the send method which 
    ajax.send ( 'AAA & username = password = 123' ); 

    ajax.onreadystatechange = function () {
         IF (ajax.readyState == == 200 is ajax.status &&. 4 ) { 
            the console.log ( 'success' ) 
        } 
    } 
the eval () methods: js code string transforming into 
    var   STR = '+. 1 + 2. 3' ;
     var n-= the eval (STR); 
    the console.log (n-); // . 6 

the JSON.parse (): json format string to pass into objects 
   var STR = '{ "name": "AAA", "Age":} 18 is' ; 
   STR =   the JSON.parse (STR); 
   Console.log(str); // {name:'aaa',age:18}

 

Guess you like

Origin www.cnblogs.com/musong-out/p/11567989.html