JQuery AJAX Demo
APP Development Group: 347072638 (Html5,app)
1. First look at a jquery AJAX Demo
HTML side:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
PHP Service side:<span style= "FONT-SIZE:12PX;" ><?Php$output = Array (); $deviceType = @$_get[' DeviceType ']? $_get[' DeviceType ': '; $version = @$_get[' version '?
$_get[' version ': 0;header (' access-control-allow-origin: * '); Note: This place is very important. <span style= "Font-family:verdana, Arial, song body; line-height:18px; Background-color:rgb (249, 249, 249); " > Because of browser security restrictions, most "Ajax" requests adhere to the same-origin policy. The request could not successfully retrieve data from a different domain, subdomain, or protocol. </span>define (' Root ', dirname (__file__)); $file = root. '/open_device_config '; $content = file_get_contents ($file);//devicetype must equal ' Android ' and version is larger than the configuration file to prompt ok! if ($deviceType = = ' Android ' && $version <= $content) {$output = array (' Code ' =>201, ' message ' = ' this vers Ion can not use, you must up grade! '); Exit (Json_encode ($output));} else{$output = Array (' Code ' =>200, ' message ' = ' This version is ok! '); Exit (Json_encode ($output));}? ></span>
Effect:
2. What is AJAX? AJAX = asynchronous JavaScript and XML (asynchronous JavaScript and XML). Ajax is the exchange of data with the server, the ability to implement a partial update of the Web page.
3. What is jquery AJAX?jquery encapsulates Ajax in a single layer.
With the JQuery AJAX method, you can request text, HTML, XML, or JSON from a remote server using HTTP Get and HTTP Post-at the same time you can load these external data directly into the selected elements of the Web page.
4. How do I use jquery AJAX?Grammar:
Jquery.post (URL,data,success (data, Textstatus, JQXHR),dataType)
number of references |
Descriptive narrative |
wr. |
Necessary. Specifies which URL to send the request to. |
data |
optional. The map or string value. Specifies the data that is sent to the server along with the request. |
success (data, Textstatus, JQXHR) |
optional. The callback function that runs when the request succeeds. |
DataType |
Optional. Specifies the data type of the expected server response. The default is to run intelligent inference (XML, JSON, script, or HTML). |
Specific Instructions
This function is shorthand for the Ajax function, which is equivalent to:
$.ajax ({ type: ' POST ', url, data, success, dataType}) ;
5. Precautions
Because of browser security restrictions. Most "Ajax" requests adhere to the same-origin policy. The request could not successfully retrieve data from a different domain, subdomain, or protocol. Let's say you're prompted in different domains:
No ' Access-control-allow-origin ' header is present on the requested resource. Origin ' http://127.0.0.1 ' is therefore not allowed access.
So the workaround:
1. Use the same domain policy, under the same domain name.
2. Set properties on the server side, such as: PHP server, Header (' access-control-allow-origin: * ');
APP Development Group: 347072638 (Html5,app)
Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.
JQuery AJAX Demo