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

基于js原生和ajax的get和post方法以及jsonp的原生写法实例

发布时间:2020-12-15 23:16:21 所属栏目:百科 来源:网络整理
导读:div class="jb51code" pre class="brush:xhtml;" login.onclick = function(){ var xhr = new XMLHttpRequest(); xhr.open("get","http://localhost/ajax2/test2.php?username="+username.value+"pwd="+pwd2.value,true); xhr.send(); xhr.onreadystatechang

<div class="jb51code">
<pre class="brush:xhtml;">
login.onclick = function(){
var xhr = new XMLHttpRequest();
xhr.open("get","http://localhost/ajax2/test2.php?username="+username.value+"&pwd="+pwd2.value,true);
xhr.send();
xhr.onreadystatechange = function(){
if (xhr.readyState == 4) {
if (xhr.status>=200 && xhr.status<300) {
alert(xhr.responseText);
};
};
}
}

ajax方法

post方法传参

它与个get方法的区别:

01 安全型。post更安全。

02 速度. get的速度快

03 数量级。 post的数量级更大一些.

具体实现:

= 200 && xhr.status < 300 ) { alert(xhr.responseText); }; }; }

原生jsonp 方法

function myCallBack(data){
console.log(data);
}

以上这篇基于js原生和ajax的get和post方法以及jsonp的原生写法实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程之家。

(编辑:李大同)

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

    推荐文章
      热点阅读