Examples of the differences between JS and Ajax get and post in use _javascript skills

Source: Internet
Author: User

The biggest difference between get and post methods is that:

The 1.get method passes the value parameter inside the URL, and the post parameter is sent inside the send

2.post method must be added

Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");

The following example looks at the Get method

Xmlhttp.open ("Get", "for.php?text=" +url,true);

The post is displayed as:

Xmlhttp.open ("POST", "for.php", true);
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");

Post and Get methods Common files

index.php

<script src= "A.js" type= "Text/javascript" ></script>
<a href= "#" onclick= "funphp100 (' O ')" >o </a>
<a href= "#" onclick= "funphp100 (' t ')" >t</a>
<a href= "#" onclick= "funphp100 (' x ')" >x</a>

Post Method File:

A.js

var xmlHttp; 
function S_xmlhttprequest () { 
if (window). ActiveXObject) { 
xmlhttp=new activexobject (' microsoft.xmlhttp ');
} else if (window. XMLHttpRequest) { 
xmlhttp=new XMLHttpRequest ();
}
}
function funphp100 (n) {
var data = "text=" +N; Multiple parameters, then add
s_xmlhttprequest ();
Xmlhttp.open ("POST", "for.php", true); 
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
xmlhttp.onreadystatechange=byphp;
Xmlhttp.send (data);
}
function byphp () {
var byphp100=xmlhttp.responsetext;
document.getElementById ("php100"). innerhtml=byphp100;

for.php:

?
echo $_post[' text '];

Get method File:

A.js:

var xmlHttp; 
function S_xmlhttprequest () { 
if (window). ActiveXObject) { 
xmlhttp=new activexobject (' microsoft.xmlhttp ');
} else if (window. XMLHttpRequest) { 
xmlhttp=new XMLHttpRequest ();
}
}
function funphp100 (URL) {
s_xmlhttprequest ();
Xmlhttp.open ("Get", "for.php?text=" +url,true); 
xmlhttp.onreadystatechange=byphp; 
Xmlhttp.send (null);
}
function byphp () {
var byphp100=xmlhttp.responsetext;
document.getElementById ("php100"). innerhtml=byphp100;

for.php:

?
echo $_get[' text '];
? >

The above is a small set to introduce JS and Ajax get and post in the use of different examples of the relevant knowledge, 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.