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'); } else if (window.xmlHttpRequest) {xmlhttp = new xmlHttpRequest (); }} fungsi funphp100 (n) {var data = "text =" +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'); } 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'];?>
Ringkasan perbedaan antara JS+AJAX, GET dan POST dalam hal penggunaan adalah semua konten yang telah saya bagikan dengan Anda. Saya harap Anda dapat memberi Anda referensi dan saya harap Anda dapat mendukung wulin.com lebih lanjut.