微信公众号网站自己做导航条,注册公司需要什么条件和手续,公司要建设网站,铜城建设集团网站其实axios和ajax都对原生的xhr进行了封装#xff0c;个人感觉还是axios简洁、方便#xff0c;尤大大都让我们转axios了#xff0c;确实对于ajax好了不少#xff0c;它支持了promise对象#xff0c;支持js最新的规范。简单易用。 !DOCTYPE html
html lang个人感觉还是axios简洁、方便尤大大都让我们转axios了确实对于ajax好了不少它支持了promise对象支持js最新的规范。简单易用。 !DOCTYPE html
html langen
headmeta charsetUTF-8meta nameviewport contentwidthdevice-width, initial-scale1.0meta http-equivX-UA-Compatible contentieedgescript srchttps://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.js/script
!-- script srchttps://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/core.js/script --!-- vue --script srchttps://cdn.jsdelivr.net/npm/vue/dist/vue.js/script!-- 推荐使用axios HTTP Client 网络通信的函数库 --script srchttps://unpkg.com/axios/dist/axios.min.js/scriptlink relstylesheet hrefhttps://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css integritysha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMOcrossoriginanonymoustitleDocument/title
/headbodydiv idapptable classtabletheadtrth学生姓名/thth学生电话/thth学生班级/thth操作/th/tr/theadtbodytr v-for(v, index) in stu :keyindextd scoperow{{v.vname}}/tdtd{{v.vphone}}/tdtd{{v.vclazz.mtitle}}/tdtdbutton typebutton clickajaxdelete(v.vid) classbtn btn-danger删除/button/td/tr/tbody/table/div
/bodyscriptnew Vue({el: #app,data: {stu: []},mounted() {axios.get(/allstu).then((r) {console.log(data:, r.data)this.stu r.data;});// $.ajax({// url:/test,// type:post,// contentType:application/json; charsetutf-8,// data:JSON.stringify(1),// success:function(r){// console.log(测试实数,r);// console.log(ok);// }// });this.xhrtest();},methods: {ajaxdelete:function(id){console.log(id,id);$.ajax({url:/delete,type:POST,contentType: application/json; charsetutf-8,data:JSON.stringify(id),succcess:(){alert(成功提交!)}})},xhrtest:function(){// 创建xhr对象let xhr ;if(window.XMLHttpRequest){xhr new XMLHttpRequest();}else{xhr new ActiveXObject(Microsoft.XMLHTTP);}//发送请求//如果修改第三个参数为true你会发现之后的xhr成功返回数据但是status不会执行if语句也就是说你看不到“这个成功了”的输出//如果改为falsegoogle浏览器会提示你这个同步的xmlHttpRequest已经过时了因为它影响了用户体验// Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end users experience.xhr.open(POST,/test,true);xhr.setRequestHeader(Content-Type, application/json);//发送请求数据xhr.send(JSON.stringify(1));// if((xhr.status 200 xhr.status 300)|| xhr.status 304){// alert(xhr.responseText);// console.log(这个成功了了)// }else{// alert(request was unsuccessful:xhr.status);// console.log(状态码,xhr.status);// console.log(xhr测试失败);// }// 返回的响应有// responseText:作为响应主体被返回的文本// responseXML:XML文档// status , statusText:状态码说明//如果为true表示异步通信,应该改为如下方式xhr.onreadystatechange function(){if(xhr.readyState 4){if((xhr.status 200 xhr.status300)||xhr.status 304){alert(xhr.responseText);console.log(ok);}else{alert(Request was unsuccessful:xhr.status);}}}}}});
/script/html 转载于:https://www.cnblogs.com/linchongatfirst/p/9551029.html