Good web front-end programmers learn to understand what AJAX is shared routes

Good programmers web front-end learning routes Share understand what AJAX is the first server

What is Server: page from our server; instance (stored in a page phpnwo above),

Let's put on a page on the Internet server, will have its own site.

1. asynchronous synchronization

Life in sync:

Asynchronous life:

In the JavaScript language, the concept of synchronous and asynchronous just the opposite.

This JavaScript in sync is: you do not complete the above code is executed, then the following code you do not perform; step by step execution, which is synchronized.

Is an asynchronous code can be executed;

The concept of process

进程≠程序

程序从开始到结束的一次执行过程叫做进程

一个进程当中,程序同时运行的多个分支,叫做线程

多线程异步执行,可以提高程序的效率

The importance of AJAX

AJAX uses proficiency === your work experience in many number of companies it seems.

2. What is AJAX

ajax front and rear ends data is an important means of interaction

Ajax full name: "Asynchronous JavaScript and XML" (Asynchronous JavaScript and XML), it is not a single technology JavaScript, but use a combination of a series of interactive web application-related technology being formed. With Ajax, we can not refresh the status update page, and asynchronous submit to enhance the user experience.

One. Ajax Overview

Ajax concept is JesseJamesGarrett invention in 2005. Which itself is not a single technology, is a collection of a bunch of technology, we are:

1.JavaScript, by the user or other related events to capture interactions with the browser

It sends a request to the server without 2.XMLHttpRequest object, without interrupting other browser tasks through the object;

3. The files on the server, save the text data to XML, HTML or JSON format;

4. Other JavaScript, to interpret the data (such as PHP MySQL data obtained from) from the server and renders it onto the page.

Because Ajax contains many features, advantages and disadvantages are also obvious. The main advantage of the following points:

1. do not need to plug-in support (usually a browser and JavaScript can be enabled by default);

2. The user experience is very good (not refresh the page to get the data can be updated);

3. To enhance the performance of Web applications (in terms of data transfer needed to do to relax, do not have to submit a whole);

4. reduce the burden on the server and the bandwidth (the transfer of some of the operations of the server to the client);

The lack of Ajax by the following:

Lack of browser support XMLHttpRequest object 1. different versions (for example, before IE5);

2. The forward and backward functions are destroyed (because Ajax forever page before or after the current page, not probability);

3. Support of the search engine is not enough (because search engine crawlers can not understand the contents of the data changes caused by JS);

4. Develop a lack of debugging tools (compared to other tools for language, JS or Ajax debugging development pitiful).

3.AJAX use

The phone then hit the order:

1. First of all have a telephone;

2. Dial;

3. speak;

4. listen to telephone the other side of the information;

// there is a Tel: Create a request object;

1.var AJAX=new XMLHttpRequest( );

@ Dial: parameter setting request;

2.AJAX.open('get','data/test.json',true);

The first argument: POST || GET

The difference between GET and POST

POST is transmission data, GET data is accepted;

PSOT security data is preferably transmitted, and GET is poor;

POST transmission data size is not limited, and the size is limited GET 2 ~ 100k.

When using GET and POST that: use the GET method, using the POST method should be operational data during data acquisition.

The third parameter: when the boolean value is true, the server requests are performed asynchronously, i.e. without waiting for the execution of the script send () method

The results of the server, but continues to execute script code;

When the boolean value is false, the server requests are synchronous, i.e. when the script send () method waits

The server returns the results, if while waiting for the process of super, then wait no longer, continues script code back!

  1. ajax.onreadystatechange = function()

    {

    if (ajax.readyState == 4 && ajax.status == 200)
    
    {
    
        func_succ(ajax.responseText);
    
    }
    
    else
    
    {
    
        //alert("ajax faild readyState:"+ajax.readyState+" status:"+ajax.status);
    
    }

    };

4.ajax.send(null);

ajax.readyStatus

0 - (uninitialized) has not been called send () method

1-- (load) has been called send () method, is sending request

2 - (Loaded) Send () method performs is completed, the entire response has been received

3 - (interactive) response is being parsed

4 - (complete) response content analysis is complete, you can call the client

Guess you like

Origin blog.51cto.com/14479068/2435138