jQuery and Ajax and serialization_jquery
About AJAX
The so-called Ajax, the full name is Asynchronous JavaScript and XML. (That is, asynchronous JS and XML)
To put it simply, it means sending and getting data without refreshing the page, and then updating the page.
Advantages of Ajax
•No plug-in support required
•Excellent user experience
•Improve the performance of web applications
•Reduce the burden on servers and bandwidth
Disadvantages of Ajax
•Insufficient browser compatibility
• Breaks the normal functionality of the browser’s forward and back buttons
•Inadequate support for search engines
•Lack of development and debugging tools
Well, these were all shortcomings from a few years ago. Technology is developing rapidly, and these shortcomings will gradually be made up. At least it is not difficult to debug Ajax now.
The core of Ajax is the XMLHttpRequest object, which is the key to Ajax implementation.
I won’t mention the traditional examples of implementing Ajax. It’s so painful that I didn’t even remember it. I searched a lot on the Internet.
About Ajax in jQuery
$.ajax() method is the Ajax method that encapsulates the most original js.
load(), $.get(), $.post() are encapsulated $.ajax()
$.getScript() and $.getJSON() are further encapsulations.
•load() method •Use: Load remote HTML code and insert it into the DOM. It is usually used to obtain static data files. The structure is: load(url [,data] [,callback]). •url is the requested address
•data is optional and is the parameter object sent to the server
•callback is a callback function, which is called whether the request succeeds or fails
•You can even add filters to the address when loading the page
$("#resDiv").load("test.html .myClass");//这个div里只载入test.html页面里面 样式为myClass 的元素 //举一个完整的例子 $(function(){ $("#resDiv").load("text.php",{name:"troy",textInfo:"hello"},function(responseText,textStatus,XMLHttpRequest){ //responseText:请求返回的内容 //textStatus: 请求状态:success、error、notmodiffied、timeout 4种 //XMLHttpRequest: XMLHttpRequest对象 }); });
•$.get() method •Obviously the calling method is different, so this function is a global function of jQuery. The previous methods and load() all operate on jQuery objects
•The $.get() method uses the GET method to make asynchronous requests. The structure is: $.get(url [,data] [,callback] [,type]) •The first three parameters will not be mentioned. The only difference is callback is only called if the request is successful
•The type parameter is the format of content returned by the server, including xml, html, script, json, text and _default
•Example
$("#send").click(function() $.get("get1.php" ,{ username:$("#username").val(), content:$("#content").val() } ,function(data,textStatus){ //data: 返回的内容,可以是XML文档、JSON文件、HTML片段 //textStatus: 请求状态:success、error、notmodiffied、timeout 4种 } ) })
•$.post() method •It plays the same way as the get method, but one is the get method and the other is the post method.
•$.getScript() method •Sometimes it is not necessary to obtain all scripts when the page is first loaded, so jQuery provides the getScript method to directly load js files.
•Example
$('#send').click(function(){ $.getScript('test.js',function(){ //do something 这个时候脚本已经加载了,不需要再对js文件进行处理 }); });
• $.getJSON() method • Used to load JSON files, the usage is the same as above, except that the json data is returned
$('#send').click(function(){ $.getJSON("myurl",function(data){ var html=""; $.each(data,function(commentIndex,comment){ html+=commentIndex+":"+comment['username']+";"; }) alert(html); }) }); //注意一下ecch这种玩法,同样是个全局函数。他的回调函数中,第一个参数为成员的索引,第二个为变量和内容
By the way, expand on JSONP for cross-domain access
$("#send").click(function(){ $.getJSON("http://www.某网站.com/services/getMyCmpJson?tags=car&tagmode=any&format=json&jsoncall back=?" ,function(data){ //某些操作 } ) })
//JSONP is an unofficial protocol, which uses a combination of json and

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.

The article discusses strategies for optimizing JavaScript performance in browsers, focusing on reducing execution time and minimizing impact on page load speed.

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

The article discusses effective JavaScript debugging using browser developer tools, focusing on setting breakpoints, using the console, and analyzing performance.

The article explains how to use source maps to debug minified JavaScript by mapping it back to the original code. It discusses enabling source maps, setting breakpoints, and using tools like Chrome DevTools and Webpack.

Once you have mastered the entry-level TypeScript tutorial, you should be able to write your own code in an IDE that supports TypeScript and compile it into JavaScript. This tutorial will dive into various data types in TypeScript. JavaScript has seven data types: Null, Undefined, Boolean, Number, String, Symbol (introduced by ES6) and Object. TypeScript defines more types on this basis, and this tutorial will cover all of them in detail. Null data type Like JavaScript, null in TypeScript

This article explores effective use of Java's Collections Framework. It emphasizes choosing appropriate collections (List, Set, Map, Queue) based on data structure, performance needs, and thread safety. Optimizing collection usage through efficient

This tutorial will explain how to create pie, ring, and bubble charts using Chart.js. Previously, we have learned four chart types of Chart.js: line chart and bar chart (tutorial 2), as well as radar chart and polar region chart (tutorial 3). Create pie and ring charts Pie charts and ring charts are ideal for showing the proportions of a whole that is divided into different parts. For example, a pie chart can be used to show the percentage of male lions, female lions and young lions in a safari, or the percentage of votes that different candidates receive in the election. Pie charts are only suitable for comparing single parameters or datasets. It should be noted that the pie chart cannot draw entities with zero value because the angle of the fan in the pie chart depends on the numerical size of the data point. This means any entity with zero proportion
