Perbedaan terbesar antara metode GET dan POST adalah:
1. Metode GET melewati parameter nilai di URL, dan parameter pos ditempatkan di dalam Kirim
2. Metode pos harus ditambahkan
xmlhttp.setRequestHeader ("tipe konten", "Aplikasi/X-WWW-Form-Urlencoded");
Contoh -contoh berikut dapat ditemukan dalam metode GET
xmlhttp.open ("get", "for.php? text ="+url, true);
Di pos, itu direpresentasikan sebagai:
xmlhttp.open ("post", "for.php", true);
xmlhttp.setRequestHeader ("tipe konten", "Aplikasi/X-WWW-Form-Urlencoded");
Posting dan Dapatkan Metode Bagikan File
index.php
<skrip src = "a.js" type = "text/javascript"> </script> <a href = "#" ontClick = "funphp100 ('o')"> o </a> <a href = "#" onClick = "funphp100 ('t')"> t </a> <a href = "#" OnClick = "funphp100 ('x')"> x </a> <div id = "php100"> </div>File Metode Posting:
A.JS
var xmlhttp; fungsi s_xmlHttpRequest () {if (window.activexObject) {xmlhttp = new ActiveXoBject ('microsoft.xmlhttp');} lain jika (window.xmlhtpRequest) {xmlHttp = new XmlHtpRequest () {xmlHttp = new XmlHtpRequest () () {xmlHttp = new XmlHtpRequest () () {xmlHttp = new XmlHtpRequest () () {xmlHttp = new XmlHtpRequest () () {xmlHttp = new XMlHtPRequestest) {xmlHttp = new XmlHtPRequest "Teks =" +n; // Untuk beberapa parameter, tambahkan s_xmlhttpRequest (); xmlhttp.open ("post", "for.php", true); xmlhttp.setRequestHeader ("tipe konten", "Aplikasi/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'];?>
Dapatkan file metode:
A.JS:
var xmlhttp; fungsi s_xmlHttpRequest () {if (window.activexObject) {xmlhttp = new ActiveXObject ('microsoft.xmlhttp');} lain jika (window.xmlhttpRequest) {xmlHttp = new XmlhttpRequest) {xmlHttp = new xmlhttprequestest) {xmlHttp = new xmlhttpRequestest) {xmlHttp = new XmlHtpRequestest) {xmlHttp = new XmlHtpRequest 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'];?>
Di atas adalah penjelasan terperinci tentang penggunaan JS, Ajax Get dan memposting yang diperkenalkan oleh editor kepada Anda. Saya harap ini akan membantu Anda. Jika Anda memiliki pertanyaan, silakan tinggalkan saya pesan dan editor akan membalas Anda tepat waktu. Terima kasih banyak atas dukungan Anda ke situs web Wulin.com!