启用Ajax插口并表明回到的主要参数。

当今端必须启用插口并回到結果时,能够应用Ajax。鸡程序猿不太懂基本原理,可是在网络上看许多实例教程很不便。在这儿,我公布一个我取得成功完成的实例。

应用id来精准定位必须改动的一部分点一下按键时开启loadDoc()涵数应用console.log(‘error’)能够在控制面板搞出爱看的物品xhttp.open(“POST”, “http://localhost:5000/users/xxxxx/me”, true);应用POST向插口推送要求,true表明异步请求xhttp.setRequestHeader(‘content-type’, ‘application/json’);设定要求的headerxhttp.send(JSON.stringify(sendData));将自变量json恢复出厂设置后传送xhttp.onreadystatechange = function()在这儿实行要想开展的html转换的实际操作,JSON.parse(xhttp.responseText)

XMLHttpRequest总体目标

Request Data

提议:

function loadDoc() { console.log('error'); var xhttp = new XMLHttpRequest(); xhttp.open("POST", "http://localhost:5000/users/xxxxx/me", true); xhttp.setRequestHeader('content-type', 'application/json'); var sendData = {"abc":123}; //将客户键入值编码序列化为字符串数组 xhttp.send(JSON.stringify(sendData)); xhttp.onreadystatechange = function() { if (xhttp.readyState == 4) { var jsonObj = JSON.parse(xhttp.responseText); document.getElementById("demo").innerHTML = jsonObj.data.adjustPeriod console.log(jsonObj.data.adjustPeriod); } }}

Ajax跨域问题处理。

在python中,在flask中建立运用案例时,加上下列编码:

from flask_cors import CORS# 建立app案例目标 app = Flask(._name._) CORS(app)

评论(0条)

刀客源码 游客评论