Now compare the pros and cons of Ajax with hidden form submissions.
1. Hide form submission, update the data after the completion of the need to go to a blank page and then the original page submitted after processing; Ajax is not, you can directly
The request way, divides into get and post:get most common HTTP request, the ordinary browsing page is the get. The parameter request for Get mode is directly followed by the URL and begins with a question mark. (JS used Window.location.search to
Service-side code there's no
.
HTML code is simpler and needs to be introduced into the jquery library
Copy Code code as follows:
Please enter user name:
JS Code
Copy Code code as follows:
/*
Copy Code code as follows:
The reason that the Ajax callback function is asynchronous causes an external direct access to the value of STR or "AAA", when "BBB" is used, the function of "BBB" can be put into the callback
A simple example of Ajax: Selecting a book will get the relevant name in real time via Ajax.
4 HTML files to the same file on the Web site.
index.html
Copy Code code as follows:
a simple Ajax instance that
Traditional Ajax Code
Copy Code code as follows:
jquery method
Code
Copy Code code as follows:
Get and Post
Code
Copy Code code as follows:
get VS. Post
Enter name and
The first step in solving IE coding problem:
DataType: ($.browser.msie)? "Text": "xml" first lets IE recognize whether the text or XML is returned
Step Two:
Copy Code code as follows:
function Parsexml (XML) {//xml IE encoding problem step
Today, I met a very painful problem. The asynchronous function $.ajax of jquery is called in one function, and then there is a section of jquery code outside the $.ajax function. Each time the code after the $.ajax is executed first.
Search on the
Copy Code code as follows:
function Initxmlrequest () {
if (window. ActiveXObject) {
XMLRequest = new ActiveXObject ("Microsoft.XMLHTTP");
} else {
if (window. XMLHttpRequest) {
XMLRequest = new XMLHttpRequest ();
}
}
}
function
Ajax friends must know that JavaScript is using UTF-8 International code, that is, each Chinese character is stored in 3 bytes, but this causes the use of Ajax to send data when garbled.One solution is to use encodeURIComponent Plus modify
Today JS practicing, want to encapsulate an AJAX request to send the object, of course, is to be compatible with the full browser. The code is as follows:
Copy Code code as follows:
var Ajax = {
Xhr:null,
Callback:null,
First, the use of IFRAME, through the document.write to produce history
Copy Code code as follows:
0
0
When you click on the button to update the page DOM (simulate AJAX submission), you
One, JS script caching problemA: This problem is one of the most common problems that you have encountered because of the modification of JS content debugging
Does not show the results of the new write code, because JS in order to speed up the page
One, what is Ajax Ajax is all called "Asynchronous JavaScript and XML" (Asynchronous JavaScript and XML), Ajax is not a technology, it is actually several technologies, each technology has its own unique this, together becomes a powerful new
The client side code is as follows:
Copy Code code as follows:
Enter the setup then get the info:
→how many once:"
→begin num: "
→end num:
Features can be improved, improve the prevention of
The technology that Ajax contains
We all know that Ajax is not a new technology, but a combination of several original technologies. It is a combination of the following technologies.
1. Use CSS and XHTML for presentation.
2. Use the DOM model for
A Load () method (simplest)
Load (Url,[data],[callback])
URL: Loaded page address
Data: Optional, sent to the server, the format is Key/value
Callback: Optional, callback function
1. The simplest application
Copy Code code as follows:
Examples are as follows:
Convert form to Ajax commit
function Ajaxsubmit (URL,FRM,FN) {
var datapara=getformjson (frm);
$.ajax ({
url:url,
type: "Post",
Data:datapara,
async:false,
dataType: ' txt ',
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.