20150227--ajax1-02

Source: Internet
Author: User
Tags tagname

Four , Ajax GET request caching issues in

In Ajax, when we use GET request in Internet Explorer to send data, the system will automatically cache the data, when the next visit, the system will automatically call the cache, the original intention is to cache the request resources to the local browser, the next time you continue to access, such as the request resource has not changed, the system automatically call the cache file, Reduce server overhead, speed access, and improve user experience. However, in some cases, we do not need to cache, then how to solve the above problem?

Review the two number summation cases in the morning:

Run found that when we change the PHP page operator is subtraction, because of IE cache problem, the system still returns the last sum of the running results, which brings us a lot of inconvenience, then how to solve the cache problem? 1 , solving caching problems with random numbers

Example code:

Operation Result:

By running this way, you find that you can solve the cache problem, but the following effects occur:

1) solve the cache problem by random number method, will generate a large number of cache files in IE browser side

2) Random numbers may also produce the same result 2 when requested, resolving cache problems by timestamp

A timestamp can compensate for the repetition of random numbers, but it also generates a large number of caches on the client.

3. through Cache last modified time of file come to Troubleshoot caching issues

By refreshing the browser, we can find that when we request the same URL address, the system automatically sends the following request header information (if-modified-since), which records the last modification time of the cache file generated by the current URL address, and when the next time the request is sent, This information is automatically appended to the request header to determine whether the last modification time of the current client-side cache file is consistent with the last modification time of server resources logged by the server, such as a consistent, call to the cache file directly, otherwise, regenerate the new resource file.

Schematic diagram is as follows:

Now that we find that when the second request of the same URL address, the system will automatically check the If-modified-since request header information, then we can set this parameter to an arbitrary value (such as 0) will never be equal to the last modification time of the file.

Example code:

The above method will also generate a cache file, but only one cache file will be generated.

4. Through setting response header information To resolve caching issues

Header ("Cache-control:no-cache, must-revalidate");

Example code:

Five , the POST request in Ajax 1 . Review the difference between get and post requests

Different sizes:

Get request has a size limit of 2k

The POST request has no size limit (in HTTP), but from PHP's point of view, it is 8M (php.ini) with a size limit, generally, the CMS or framework will usually 2M limit the upload file.

Different parameters:

Get request whose argument is appended at the end of the URL

The POST request whose arguments are appended in a blank line

Security aspects:

Post security is higher than GET request 2,POST request in Ajax

The POST request in Ajax is six steps away:

1) Creating an Ajax object

2) Set the callback function

3) Initializing Ajax objects

4) Set the request header information

5) Sending Ajax requests

6) Judgment and Example 1: Two-number summation via Ajax

Demo07.html

demo07.php

Operation Result:

Example 2: No refresh input function

Demo08.html

demo08.php

Six , Ajax the XML in 1. What is XML

A: Extensible Markup Language 2,themain role of XML?

Answer: Transfer data and store data 3,PHP and XML

PHP DOM Model parsing XML

PHP simplexml to parse XML 4,php DOM

"Polygon" "string" "point"

$dom =new DOMDocument ();

$dom->load ($STR);

$node = $dom->getelementsbytagname ("TagName");

$value = $node >item (0)->nodevalue 5,PHP SimpleXML

$xml =simplexml_load_string ($STR);

$first = $xml->first;

$second = $xml->second; 6 , the DOM model in JavaScript

Standard DOM and non-standard DOM models

PHP DOM model belongs to non-standard DOM model

Javascript DOM model belongs to standard DOM model

It can be found by the structure that the standard DOM model is more complex to parse than a nonstandard Dom 7, parsing XML in JavaScript

var xml=xmlhttp.responsexml;

Node=xml.getelementsbytagname ("TagName");

Node[0].childnodes[0].nodevalue;

Childnodes[]: The collection of all child elements of the current element, itself an array Example 1: Two numbers of arithmetic

Demo09.html

demo09.php

Operation Result:

Example 2: get categories by Ajax+xml information, and store it in the Select drop-down list

Demo10.html

demo10.php

Operation Result:

Seven , Job

Ajax+smarty Complete no-refresh page-breaking effect

20150227--ajax1-02

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.