Ajax example tutorial in jquery

jQuery

jQuery is a fast, concise JavaScript framework that is an excellent JavaScript codebase (or JavaScript framework) after Prototype. The goal of jQuery design is "write Less, Do More", which advocates writing less code and doing more. It encapsulates the functional code commonly used by JavaScript, providing a simple JavaScript design pattern that optimizes HTML document manipulation, event handling, animation design, and Ajax interaction.

The core features of jQuery can be summarized as: a unique chained syntax and a short and clear multi-function interface; an efficient and flexible css selector, and can extend the CSS selector; has a convenient plug-in extension mechanism and a rich plug-in. jQuery is compatible with all major browsers, such as IE 6.0+, FF 1.5+, Safari 2.0+, Opera 9.0+, etc.

Ajax example tutorial in jquery

Ajax

Ajax development is very different from traditional B/S development. These differences introduce new programming problems, the biggest problem being ease of use. Because Ajax relies on browser-based JavaScript and XML, browser compatibility and supported standards have become as important as JavaScript's runtime performance. Much of these problems come from a combination of browsers, servers, and technologies, so you must understand how best to use them.

Combining a variety of changing technologies and a strongly coupled client-side environment, Ajax proposes a new approach to development. Ajax developers must understand the traditional MVC architecture, which limits the boundaries between application hierarchies. At the same time, developers need to consider the outside of the B/S environment and use Ajax technology to reshape the MVC boundaries. Most importantly, Ajax developers must ban web applications from being considered as a single page in a collection of pages. Once the scope between the UI design and the service architecture is strictly separated, developers need to update and change the collection of technologies.

A simple tutorial for ajax in JQuery

When dealing with a new technology, we must first ask ourselves four questions. If we can learn and understand the four questions, then you can say that this new technology has already completed the initial grasp. Below we have these four questions. So how should ajax learn? If you have already read the tutorial on using ajax in JS that I wrote, I believe you have a basic understanding of ajax. Then you can look at the fourth part directly to save your time.

First, what is ajax?

AJAX = Asynchronous JavaScript and XML. A technology for creating fast, dynamic web pages. AJAX can make web pages asynchronously update by doing a small amount of data exchange with the server in the background. This means that some part of the page can be updated without reloading the entire page. Traditional web pages (without AJAX) If you need to update content, you must reload the entire web page. There are many examples of applications that use AJAX: Sina Weibo, Google Maps, Kaixin, and more.

Second, where is the ajax used?

Simply put, it is the place to connect to the database, but the amount of information transmitted by the connection database is very small, there is no need to refresh the entire page. This type is suitable for using ajax, which avoids the waste of resources caused by the entire page of the attribute.

Third, why use ajax?

Reduce the burden on the server and count as needed to minimize the burden of redundant requests and responses on the service. Innocent new update page to reduce user psychology and actual waiting time. Bring a better user experience. The work that some of the previous servers can bear can be passed on to the client, and the client's idle capacity can be used to reduce the burden on the server and the sketch, saving space and broadband rental costs. External data can be called. Based on standardized and widely supported technologies, there is no need to download plugins or applets. Further facilitate the separation of page presentation and data.

Fourth, how to use ajax in JS? Basic knowledge we need to know when using

1. What is JQuery?

Is a JavaScript class library that encapsulates a lot of JavaScript underlying code.

2, JQuery's Ajax operation , encapsulates JavaScript's underlying Ajax operations, provides two methods for operation

The first is the underlying $.ajax() operation.

[html] view plain copy$.ajax({

Url: "url",

Type: "get",

dataType: "json",

Data:{

userID: "1"

},

Success:funcTIon(response){

},

Error: funcTIon() {

}

});

[html] view plain copy

The second is the shortcut operation $.get(). .$.post(). . .

[html] view plain copy$.get(

"url",

{userID: "123"},

funcTIon(response) {

}

)

[html] view plain copy$.post(

"url",

{userID: "123"},

funcTIon(response) {

}

)

Simple instance

[html] view plain copy "! DOCTYPE html

Html lang=“en”

"head"

"meta charset="UTF-8"

Title Title "/title"

Link rel=“stylesheet” href=“js/lib/bootstrap-3.3.7-dist/css/bootstrap.min.css”

"script src="js/lib/jquery2.2.4/jquery-2.2.4.js""//script"

"script src="js/lib/bootstrap-3.3.7-dist/js/bootstrap.min.js""//script

"style"

.thumbnail{

Max-height: 350px;

Height:330px;

Overflow:hidden;

}

.thumbnail 》 img{

Width: 140px; height: 140px;

}

"/style"

/head

"body"

"div class="container"

"div class="row hotgoodslist"

"div class="page-header"

"h1" hot-selling goods "small" annual hot-selling goods list "/small" "/h1"

"/div"

"! --"div class="col-sm-4 col-md-3"

"div class="thumbnail"

"img src="..." alt=“...”

"div class="caption"

"h3" ¥ "span" 400 "/span" "/h3"

"p" trade name "/p"

"p"

"a href=“#” class=“btn btn-danger” role=“button””Add to cart “/a”

"a href=“#” class=“btn btn-primary” role=“button”” Buy Now “/a”

"/p"

"/div"

"/div"

"/div"--"

"/div"

"div class="row shirt"

"div class="page-header"

"h1" shirt "small" many brands gathered, business and leisure preferred "/small" "/h1"

"/div"

"/div"

"/div"

"script"

$(function() {

/* Load hot item list page*/

$.ajax({

Url: "http://datainfo.duapp.com/shopdata/getGoods.php?callback=?",

Type: "get",

dataType: "jsonp",

Success:function(resp) {

Console.log(resp);

For(var i = 0; i " resp.length; i ++) {

// Add items to the DOM operation

Var $goodsBox = $("div").addClass("col-md-3").addClass("col-sm-4");

Var $thumbnail = $(""div"").addClass("thumbnail");

Var $img = $("img"").attr("src", resp[i].goodsListImg);

Var $caption = $("div"").addClass("caption");

Var $priceSpan = $("span").text(resp[i].price);

Var $price = $("h3"").text("Â¥").append($priceSpan);

Var $name = $("p"").text(resp[i].goodsName);

Var $id = $("p"").text(resp[i].goodsID).css("visible", "hidden");

Var $addCart = $("button"").addClass("btn").addClass("btn-danger").text("Add to Cart");

Var $buyNow = $("button"").addClass("btn").addClass("btn-primary").text("Buy Now");

$caption.append($price);

$caption.append($name);

$caption.append($id);

$thumbnail.append($img);

$thumbnail.append($caption);

$thumbnail.append($addCart);

$thumbnail.append($buyNow);

$goodsBox.append($thumbnail)

$(".hotgoodslist").append($goodsBox);

}

}

});

/*

Load shirt item list page

*/

$.ajax({

Url: "http://datainfo.duapp.com/shopdata/getGoods.php?callback=?",

Type: "get",

Data:{

classID: 1

},

dataType: "jsonp",

Success:function(resp) {

Console.log(resp);

For(var i = 0; i " resp.length; i ++) {

// Add items to the DOM operation

Var $goodsBox = $("div").addClass("col-md-3").addClass("col-sm-4");

Var $thumbnail = $(""div"").addClass("thumbnail");

Var $img = $("img"").attr("src", resp[i].goodsListImg);

Var $caption = $("div"").addClass("caption");

Var $priceSpan = $("span").text(resp[i].price);

Var $price = $("h3"").append($priceSpan);

Var $name = $("p"").text(resp[i].goodsName);

Var $id = $("p"").text(resp[i].goodsID).css("visible", "hidden");

$caption.append($price);

$caption.append($name);

$caption.append($id);

$thumbnail.append($img);

$thumbnail.append($caption);

$goodsBox.append($thumbnail)

$(".shirt").append($goodsBox);

}

}

});

})

"/script"

"/body"

"/html"

Horn Speaker For Monitoring

This speaker series is made from robust,virtually indestructible ABS enclosure,and adjustable metal bracket offering maximum protection against shock and weather making it ideal for mounting in extreme outdoor conditions.
It can provide public address announcements and remote paging via network video surveillance applications.
Ideal for remote monitoring applications,such as at factories, building sites,
airports and shopping centres or in exposed outdoor installations.
With volume control
All are fitted with a sturdy,adjustable mounting bracket.horn speaker for monitoring

Horn Speaker Monitor,Monitor horn,Monitor horn speaker,Horn Speaker for Remote Monitoring Applications,Monitor horn speakers

Taixing Minsheng Electronic Co.,Ltd. , https://www.ms-speakers.com