Home  >  Article  >  Web Front-end  >  How many common AJAX interview questions do you know? 12 common ajax interview questions and their answers

How many common AJAX interview questions do you know? 12 common ajax interview questions and their answers

寻∝梦
寻∝梦Original
2018-09-10 11:57:435367browse

This article mainly talks about the interview questions and answers about ajax. You can read more and see how the interviewers asked the questions and what the correct answers are. . Let’s take a look at this article now

[Related topic recommendations: ajax interview questions (2020)]

1. At work Will it interact with the background? Then can you talk about a few parameters in the encapsulated ajax?

url: The address to send the request.

type: The request method (post or get) defaults to get.

async: Synchronous asynchronous requests, default true, all requests are asynchronous requests.

timeout: timeout setting, unit millisecond

data: required to be a parameter of Object or String type, data sent to the server

cache: default is true (when dataType When it is script, the default is false), setting it to false will not load the request information from the browser cache.

dataType: The data type expected to be returned by the server.

The available types are as follows:

     xml: Returns an XML document, which can be processed with JQuery.

html: Returns plain text HTML information; the included script tag will be executed when inserted into the DOM.

script: Returns plain text JavaScript code. Results are not automatically cached.

json: Return JSON data.

jsonp: JSONP format. When calling a function using JSONP format, such as myurl?callback=?, JQuery will automatically replace the last "?" with the correct function name to execute the callback function.

text: Returns a plain text string.

success: The callback function called after the request is successful, has two parameters.

(1) Data returned by the server and processed according to the dataType parameter.

(2) A string describing the status.

error: The parameter is required to be Function type, and the function is called when the request fails. This function has 3 parameters

(1) XMLHttpRequest object

(2) Error message

(3) Captured error object (optional)

complete :function(XMLHttpRequest,status){ //Final execution parameters after the request is completed

2.json data How to deal with its format Do you have a fixed format in your previous work? If I Send a request to delete a piece of data in the data. How do I know if the deletion is successful, or where will it be displayed after deletion?

JSON.parse() Convert to JSON object, parse according to the data, and put it on the page.

Format: JSON string spliced ​​together with {} and []

Send a request to delete data, the background will return the processing result, and the frontend will judge whether it is successful based on the returned result, and then process the page elements.

3. Have you ever encountered this situation? In the IE browser, the background image data has changed but the client has not changed. How to deal with it? He reminded that the browser's cache

JQuery.ajax() method, set cache to false, will not load the request from the browser cache,

or use the post method to request data, It will not be cached, and the data will be requested again every time

4. Implementation ideas of the tab

Mouse hover time, call method, pass in this, for all Hide part of the content of the tab, perform display operations on this, and control the display

5. Cascading implementation ideas

Generally, regional data uses two-dimensional arrays Store, obtain it from the background and store it later.

Find the corresponding two-dimensional array data according to the option of the first drop-down box, loop new Option() add into the drop-down box

6. Ideas for implementing carousel images

The first one:

Name the pictures in order, and use a timer to change the path of the pictures every few seconds

Second type:

Use seamless scrolling technology to put all pictures into the page. The timer performs scrolling and determines the scroll distance by taking the remainder (%). The width of the picture is equal to 0 and the timer is paused. , how many seconds before starting the timer.

7. Talk about what you understand about bootstrap

Bootstrap is developed based on HTML5 and CSS3. It is more personalized and humanized based on jQuery. , you only need to give the tag a corresponding Class name to form a set of Bootstrap's own unique website style, and it is compatible with most jQuery plug-ins.

8. The difference between angularjs and JQ

JQ gets it first and then uses it.

Use Angularjs directly

9.The difference between JQmobile and JQ

jQuery Mobile 是创建移动 web 应用程序的框架。jQuery Mobile 适用于所有流行的智能手机和平板电脑。jQuery Mobile 使用 HTML5 和 CSS3 通过尽可能少的脚本对页面进行布局

(1) jQuery is a js library that mainly provides selectors, property modification, event binding, etc.
(2) jQuery UI is a plug-in designed based on jQuery and utilizing the extensibility of jQuery. Provides some commonly used interface elements, such as dialog boxes, dragging behaviors, resizing behaviors, etc.
(3) jQuery itself focuses on the background and does not have a beautiful interface, while jQuery UI supplements the shortcomings of the former. It provides a gorgeous display interface, making it easier for people to accept. There is both a powerful backstage and a gorgeous frontstage. jQuery UI is a jQuery plug-in, but it specifically refers to the UI-oriented plug-in officially maintained by jQuery.

10. The four parts of ajax:

var xmlhttp = new XMLHttpRequest();
xmlhttp.open("post||get","URL",true||false);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.onreadystatechange = callBack;
xmlhttp.send(null);

11.What is the data type received by ajax?

String

JSON string

JSON object

12. Where ajax is needed and where it is not, what are the advantages and disadvantages of ajax ?

                                                                                                                                                                                                                                                   that the form can be completed automatically when processing data asynchronously, using Ajax. For functions such as refreshing and querying, you don’t need Ajax

Advantages:

<1>.No refresh update data.

The biggest advantage of AJAX is that it can communicate with the server to maintain data without refreshing the entire page. This allows web applications to respond to user interactions more quickly and avoids sending unchanged information over the network, reducing user waiting time and bringing a very good user experience.
<2>. Communicate with the server asynchronously.
AJAX uses an asynchronous method to communicate with the server, without interrupting the user's operation, and has a faster response capability. Optimizes the communication between Browser and Server, reducing unnecessary data transmission, time and data traffic on the network.
<3>. Front-end and back-end load balancing.
AJAX can transfer some of the work previously burdened by the server to the client, using the client's idle capabilities to process it, reducing the burden on the server and bandwidth, and saving space and broadband rental costs. And to reduce the burden on the server, the principle of AJAX is to "get data on demand", which can minimize the burden on the server caused by redundant requests and responses and improve site performance.
<4>. Widely supported based on standards.
AJAX is based on standardized and widely supported technology and does not require downloading browser plug-ins or applets, but requires the customer to allow JavaScript to be executed on the browser. As Ajax matures, some program libraries that simplify the use of Ajax have also come out. Likewise, another assistive programming technology has emerged to provide alternative functionality for users who do not support JavaScript.
<5>. The interface is separated from the application.
Ajax separates the interface and application in the WEB (it can also be said to separate data and presentation), which is conducive to division of labor and cooperation, reducing WEB application errors caused by non-technical personnel modifying the page, and improving Efficiency and more suitable for current publishing systems.

shortcoming:

<1>.AJAX kills the Back and History functions, which is a destruction of the browser mechanism.
In the case of dynamically updated pages, users cannot return to the previous page state because the browser can only remember static pages in the history. The difference between a page that has been read completely and a page that has been dynamically modified is very subtle; users will often expect that clicking the back button will cancel their previous operation, but in an Ajax application, this will not be possible. .
The back button is an important function of a standard web site, but it cannot cooperate well with js. This is a serious problem caused by Ajax, because users often hope to cancel the previous operation by going back. So is there any solution to this problem? The answer is yes. Those who have used Gmail know that the Ajax technology used under Gmail solves this problem. You can go back under Gmail. However, it does not change the mechanism of Ajax. It is just a stupid but effective one. The way to do this is by creating or using a hidden IFRAME to reproduce the changes on the page when the user clicks the back button to access the history. (For example, when the user clicks back in Google Maps, it searches in a hidden IFRAME and then reflects the search results onto the Ajax element to restore the application state to what it was at that time.)
However, although this problem can be solved, the development cost it brings is very high, and is contrary to the rapid development required by the Ajax framework. This is a very serious problem caused by Ajax.
A related point is that using dynamic page updates makes it difficult for users to save a specific state to favorites. Solutions to this problem have also emerged, most of which use URL fragment identifiers (often called anchors, the part after the # in the URL) to keep track and allow the user to return to a specified application state. (Many browsers allow JavaScript to dynamically update anchors, which allows Ajax applications to update the anchor simultaneously with the displayed content.) These solutions also resolve many of the arguments about not supporting the back button. (If you want to see more, go to the PHP Chinese website AJAX Development Manual column to learn)

<2>.AJAX security issues.
AJAX technology not only brings a good user experience to users, but also brings new security threats to IT companies. Ajax technology is like establishing a direct channel for enterprise data. This allows developers to inadvertently expose more data and server logic than before. Ajax logic can be hidden from client-side security scanning technologies, allowing hackers to create new attacks from remote servers. Ajax is also difficult to avoid some known security weaknesses, such as cross-site scripting attacks, SQL injection attacks, and Credentials-based security vulnerabilities.
<3>. Weak support for search engines.
The support for search engines is relatively weak. If used improperly, AJAX will increase network data traffic, thus reducing the performance of the entire system.
<4>. Destroy the exception handling mechanism of the program.
At least from the current perspective, Ajax frameworks such as Ajax.dll and Ajaxpro.dll will destroy the exception mechanism of the program. Regarding this problem, I have encountered it during the development process, but after checking, there is almost no relevant introduction on the Internet. Later, we did an experiment and used Ajax and traditional form submission modes to delete a piece of data... which brought great difficulties to our debugging.
<5>. Violates the original intention of URL and resource positioning.
For example, if I give you a URL address, if Ajax technology is used, maybe what you see under the URL address is different from what I see under this URL address. This is contrary to the original intention of resource positioning.
<6>.AJAX does not support mobile devices well.
Some handheld devices (such as mobile phones, PDAs, etc.) currently do not support Ajax very well. For example, when we open a website using Ajax technology on the mobile phone’s browser, it currently does not support it. of.
<7>. The client is too fat and too much client code causes development costs.
It is complex to write and error-prone; there are many redundant codes (it is a common problem of AJAX to include js files in layers, plus a lot of server-side code in the past is now placed on the client); it destroys the Web of the original standards.

This article ends here (if you want to see more, go to the PHP Chinese website AJAX User Manual column to learn). If you have any questions You can leave a message below to ask questions.

The above is the detailed content of How many common AJAX interview questions do you know? 12 common ajax interview questions and their answers. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn