Let's take a look at an official example.
Instance
Use AJAX requests to get JSON data and output the results:
The code is as follows
Copy Code
$ ("button"). Click (function () {$.getjson ("Demo_ajax_json.js", function (
About Ajax Cross-domain problem, sorted out today, in fact, there are other ways, personally recommended the following 4 kinds. Please refer to: Ajax cross-domain instanceOne, the traditional Ajax method
1,js Code
$ ("#ajax"). Click (function () {$
When the mobile Web page is too long, you can block the content and load it with Ajax.
The main ideas are as follows: Store the pages that need to be loaded in a new page, main code:
header ("Access-control-allow-origin: *");
Header
First, the XMLHttpRequest of the original ecology
The code is as follows
Copy Code
" method= "POST" >
Two, jquery Ajax.post
1.jQuery $.post () method
The $.post () method requests data from the server via an
Using jquery for easy access to Ajax asynchronous data, the following example is an AJAX feature similar to the type user name
jquery.post (URL, [data], [callback], [type]): asynchronous request using POST method
Parameters:
URL (String): The URL
Index.html
The code is as follows
Copy Code
)/ig; var srcre =/ssrc= ([' "]) (. *?) 1/i; var typere =/stype= ([' "]) (. *?) 1/i; Var match; While match = re.exec (html)) { var attrs = match[1]; var srcmatch =
Usually jquery's submit form submission is not intercepted, but the asynchronous submission with jquery Ajax is rejected, and since the problem is caused by an asynchronous commit, it's a good solution because the jquery Ajax method provides the
In jquery we want to use asynchronous or synchronous transmissions, as long as you set the true or false settings in the AJAX parameter async
example, do not use asynchronous transmissions
The code is as follows
Copy Code
var info = document.getElementById ("TXT"). Value;
Jquery.ajax ({
Type: ' Get ',
URL: ' http://localhost:8080/jdom/hehe.do?act= page special effects on ',
Data: "&info=" +info,
Cache:false,
DataType: ' JSON ',//Specifying return type
Client:
Using $.getjson () when transferring the first parameter, that is, the URL, if a cross-domain request must have a parameter with a value of "?", such as:
The code is as follows
Copy Code
$.getjson ("Http://202.19
jquery Ajax No Refresh data submission instance
name "this field is required.
return emailthis field is required.
return phone"this field is required.
You may notice that I have included an ID contact_form the div around the entire form of
Ajax more focused on the front page asynchronous display of the Background database field, the main idea is similar to the previous article, focusing on the DAL layer to get stored in the process of the table collection dataset, in general stored
The code is as follows
Copy Code
var url = "B.aspx";var param = "a=1&b=2";var ret = getremotetext (URL, param, ' post ');This ret is what b.aspx returns, use it. //Create XMLHTTP Object Function Createxmlhttp () { if window.
Load an XML file with XML HTTP
When you send a xmlhttprequest to retrieve data, the user clicks a button.
using the HttpRequest object
Status:
status text:
Response:
get xml
Get the results.
Using the HttpRequest Object
Status: A
How AJAX thumb ups are implementedYou can use custom fields to save the number of likes, and use cookies to disable repeated likes.WordPress does not use plug-ins to implement the AJAX thumb up processWe directly add the following code to your
First, you must create a website to create the following files: Web forms (Default. asp tutorial x), JScript File (ajax. js), Web service (SayHelloService. asmx), Class (Hello. cs)(Add: you need to add a Microsoft. Web. Preview. dll file to download
Jquery's tool functions encapsulate the processing methods of commonly used strings, numbers, arrays, and objects. Below are some of the commonly used methods:String operation The code is as follows:Copy code Var str = 'www.111cn.net ';Console.
Jquery encapsulates three layers of ajax:Layer 1: $. ajax, Layer 2:. load $. get, $. post, Layer 3: $. getScript, $. getJsonFirst, let's learn how to use. load:Format: load (url [, data] [, callback]) The simplest get method to get text content
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.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service