PHP---------Ajax

Source: Internet
Author: User

Ajax

When using AJAX, it is necessary to think of jquery, must have jquery package <script src= "Jquery-1.11.2.min.js" ></script>

Use Ajax to make a simple example:

Displays a drop-down list:

<title> Untitled Document </title>

<script src= ". /0623kejian/jquery-1.11.2.min.js "></script>

<body>

<select id= "SEL" >

</select><!--Select Displays the contents of the National table--

<!--we did not use Ajax before, it was possible to use the direct embedding of PHP code. However, in this HTML page, because we embed the PHP code, if you want to refresh the data inside, we need to re-brush the page, but, using AJAX, you do not have to brush the page, Ajax use JS, jquery way to manipulate the contents of the page, so that a page can not be refreshed. -

<!--how to tune the data in the database, display it in the drop-down list, use jquery to <script type= "Text/javascript" >-->

<!--to check the database, not embedded in the PHP code, you need to use JS or jquery to call something, the desired value is returned--

<!--Ajax is the equivalent of a factory or workshop, give him a thing, and then it returns a thing I want, the process between this, is to operate the database, operation database, I specifically do a page, to do database, this page is called the processing page, specifically to do a database operation of the page, Then JS this end, only responsible for it to pass a value, and then receive a return value. Another processing page, the function of the page to implement is to receive the value you pass, and then find out the results you want, return, it is over. -

<!--is our original page, to convert to two pages, a special to operate the database is the PHP code, the other is the end of JS, JS this one end to control the page display. -

</body>

<!--because you want to display the contents of the table and put it in the select, so after the page is loaded, it executes, not written in the click Page. -

<script type= "Text/javascript" >

$ (document). Ready (function (e) {

<!--when the page is loaded, it executes and executes what????? -

<!--Call this method Ajac (), this is the method of Ajac, call this method, need a parameter, this parameter is a JSON type of data, so inside to write a curly brace. -

$.ajac ({

URL: "chuli.php",//processing the page, that is, Ajac need to use which page to process the data, need a processing page

date:{},//Pass the value that is, to use the processing page, to process the data, the processing page to pass to it which value, the value to commit

Type: "POST",//how the value to be submitted is passed

DataType: "TEXT",//return value type, a total of three

Success:function (s) {//This function is called::: Callback function

Success is the meaning of success. After successful invocation of the processing page, followed by a function () method, that is, the Ajac, after the call succeeds, come to execute function () {} to execute this method, when executing this method, there is a return value came, this return value is the parameter of this method, called date.     This function is called::: callback function because this AJAC invokes the processing page, after the processing page completes, returns a value, comes over to call: function (date) {} method to execute, so this method is called the callback function. Success:function (s) (s) This is a formal parameter, it's a return value, write it casually.

Its order of execution is:::

That is,when the Ajac executes, it executes the Ajac method, executes to the face, it invokes the processing page, completes the corresponding operation, completes, because has the return value, it passes over the return value, then comes over calls the success method. In other words, this function ajac it execution, not from the beginning to the end, the middle of the execution of a processing page, must be processed after processing the page, down to continue to go.

alert (str);

}

PHP---------Ajax

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.