加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Js+Ajax,Get和Post在使用上的区别小结

发布时间:2020-12-15 23:26:14 所属栏目:百科 来源:网络整理
导读:get和post方法最大的不同在于: 1.get方法传值参数在url里面,而post参数放send里面 2.post方法必须加上 xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 在post里面表现为: POST和GET方法共用文件 index.php POST方法文件

get和post方法最大的不同在于:

1.get方法传值参数在url里面,而post参数放send里面

2.post方法必须加上

xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

POST和GET方法共用文件

index.php

POST方法文件:

a.js

function funphp100(n){
var data = "text=" +n;  //多个参数的,往后加
S_xmlhttprequest();
xmlHttp.open("POST","application/x-www-form-urlencoded");
xmlHttp.onreadystatechange=byphp;
xmlHttp.send(data);
}

function byphp(){
var byphp100=xmlHttp.responseText;
document.getElementById("php100").innerHTML=byphp100;
}

for.php:

GET方法文件:

a.js:

function funphp100(url){
S_xmlhttprequest();
xmlHttp.open("GET",true);
xmlHttp.onreadystatechange=byphp;
xmlHttp.send(null);
}

function byphp(){
var byphp100=xmlHttp.responseText;
document.getElementById("php100").innerHTML=byphp100;
}

for.php:

以上这篇Js+Ajax,Get和Post在使用上的区别小结就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程之家。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读