国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

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

2019-11-19 15:09:57
字體:
來源:轉載
供稿:網友
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方法

btn.onclick = function(){ajax(    "GET",    "http://localhost/ajax2/my02.php",    {xingming:xingming.value,pwd:pwd.value},    function(data){console.log(data);},function(errCode){console.log(errCode);})

post方法傳參

它與個get方法的區別:

01 安全型。post更安全。

02 速度. get的速度快

03 數量級。 post的數量級更大一些.

具體實現:

var xhr = new XMLHttpRequest();xhr.open("post","http://localhost/ajax2/login2.php",true);var data = {username:username1.value,pwd:pwd1.value}// 設置請求頭 告訴服務器發給他的數據是json格式xhr.setRequestHeader("content-type","application/json");xhr.send( JSON.stringify(data) );xhr.onreadystatechange = function(){if (xhr.readyState == 4) {if ( xhr.status >= 200 && xhr.status < 300 ) {alert(xhr.responseText);};};}

原生jsonp 方法

var sc = document.createElement("script");sc.type = "text/javascript";document.body.appendChild(sc);sc.src = "http://localhost/ajax2/jsonp.php?cb=myCallBack";function myCallBack(data){console.log(data);}

以上這篇基于js原生和ajax的get和post方法以及jsonp的原生寫法實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 公主岭市| 雅安市| 新巴尔虎左旗| 皋兰县| 宝应县| 禄丰县| 勃利县| 衡山县| 区。| 特克斯县| 新民市| 广平县| 法库县| 思南县| 修水县| 库伦旗| 合阳县| 临湘市| 邯郸市| 商洛市| 樟树市| 九龙城区| 辰溪县| 德惠市| 鹤山市| 迁安市| 呼和浩特市| 前郭尔| 黄浦区| 乐昌市| 社旗县| 阿合奇县| 启东市| 抚州市| 翁牛特旗| 上虞市| 建湖县| 周至县| 霍山县| 甘洛县| 望都县|