search
HomeWeb Front-endJS TutorialHow many common AJAX interview questions do you know? 12 common ajax interview questions and their answers

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:

.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.
. 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.
. 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.
. 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.
. 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:

.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)

.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.
. 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.
. 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.
. 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.
.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.
. 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
Python vs. JavaScript: A Comparative Analysis for DevelopersPython vs. JavaScript: A Comparative Analysis for DevelopersMay 09, 2025 am 12:22 AM

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Python vs. JavaScript: Choosing the Right Tool for the JobPython vs. JavaScript: Choosing the Right Tool for the JobMay 08, 2025 am 12:10 AM

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript: Understanding the Strengths of EachPython and JavaScript: Understanding the Strengths of EachMay 06, 2025 am 12:15 AM

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScript's Core: Is It Built on C or C  ?JavaScript's Core: Is It Built on C or C ?May 05, 2025 am 12:07 AM

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript Applications: From Front-End to Back-EndJavaScript Applications: From Front-End to Back-EndMay 04, 2025 am 12:12 AM

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Python vs. JavaScript: Which Language Should You Learn?Python vs. JavaScript: Which Language Should You Learn?May 03, 2025 am 12:10 AM

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

JavaScript Frameworks: Powering Modern Web DevelopmentJavaScript Frameworks: Powering Modern Web DevelopmentMay 02, 2025 am 12:04 AM

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

The Relationship Between JavaScript, C  , and BrowsersThe Relationship Between JavaScript, C , and BrowsersMay 01, 2025 am 12:06 AM

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools