Talk about Ajax submit form Form view and understanding _ajax related

Source: Internet
Author: User

Ajax (Ajax development)

Ajax, "Asynchronous JavaScript and XML" (Asynchronous JavaScript and XML), refers to a web development technology that creates interactive Web applications.

AJAX = Asynchronous JavaScript and XML (a subset of standard generic markup languages).

AJAX is a technique for creating fast-moving web pages.

AJAX enables asynchronous updating of Web pages by making a small amount of data exchange in the background with the server. This means you can update portions of a Web page without reloading the entire page.

The time to learn the code is not short, but it is very rare to use Ajax, and then specifically to understand, the following is as a new Ajax novice to the view and understanding of Ajax.

Ajax, asynchronous requests that Ajax can make a Web page asynchronous, by making a small amount of data exchange in the background with the server. This means you can update portions of a Web page without reloading the entire page.

Recently I tested the AJAX submission Form form, the form submission has post and get two use more is the Post method, although compared with post, get is simpler and faster, and in most cases can be used.

However, it is more efficient to use POST requests in the following situations:

1. Cannot use cached files (update files or databases on the server)

2. Send a large amount of data to the server (POST no data limit)

3. Post is more stable and reliable than get when sending user input with unknown characters

Submit a Form $get way

The Get () method loads information through a remote HTTP GET request

Format

$ (selector). Get (Url,data,success (RESPONSE,STATUS,XHR), DataType)

Like what:

Request demo.php Web page, transfer 2 parameters, ignore return value:

$.get ("demo.php", {name: "John", Time: "2pm"});

demo.php is the URL address for sending the request

{Name: "John", Time: "2pm"} data to be sent to the server.

Submit a Form $POST way

$.post

Jquery.post (URL, [data], [callback], [Type]): Asynchronous request using POST method

Parameters:

URL (String): The URL address where the request is sent.

Data (MAP): (optional) The information to be sent to the server, expressed as a Key/value key-value pair.

Callback (function): (optional) the callback function (which is invoked only if the response return state is success) when loading succeeds.

For example, when registering, the use of the Verification code

<script type= "Text/javascript" >
function redirect (URL) {
location.href = URL;
}
$ ("#code_btn"). Click (function () {
var tel = $ ("#username"). Val ();
if (tel = = "") {
alert ("Please enter the correct mobile number as an account for registration");
$ ("#username"). focus ();
return false;
}
if (!) ( /^1[3|4|5|8| 7][0-9]\d{4,8}$/.test (tel)) {
alert ("Please use the correct mobile phone number as an account to register!") ");
$ ("#username"). focus ();
return false;
var codenum = $ ("#code"). Val ();
$.post (' {app_path}index.php?m=member&c=index&a=public_send_message ', {tel:tel,codenum:codenum}, function (Result) {
//Console.log (result);
})
TIMEP ();
});
function Timep (j) {
$ ("#code_btn"). attr (' disabled ', ' true ');
$ ("#code_btn"). Val (j+ "seconds");
Time=setinterval (function () {
j=j-1;
$ ("#code_btn"). Val (j+ "seconds");
if (j==0) {
$ ("#code_btn"). Removeattr (' disabled ');
Clearinterval (time);
j=60;
$ ("#code_btn"). Val ("Click to obtain authentication code");}
</script>

App_path}index.php?m=member&c=index&a=public_send_message is the URL address for sending the request

{Tel:tel,codenum:codenum} is the data to be sent to the server, expressed as a Key/value key-value pair.

The above is a small set of Ajax to introduce the form of the introduction form of the view and understanding, I hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.