会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133628个问题
JAVA 全系列/第四阶段:数据库与AI协同技术实战/JDBC技术 19381楼

输出的不应该是字典吗,怎么会把代码打印出来了?

image.png

from flask import Flask,request,render_template

app = Flask(__name__)

@app.route('/state',methods=['GET','PSOT'])

def state():
    if request.method == 'GET':
        return render_template('04-Ajex的状态码与JSON响应处理.html')
    elif request.method == 'POST':
        # return 'post请求成功'
        return '{"name":"吕小布","age":20}'
if __name__ == "__main__":
    app.run(debug=True)
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="button" value="传递数据-str" onclick="submitform()">
    <script>
        function submitform(){
            url='/state'
            var xhr=new XMLHttpRequest()
            xhr.open('get',url)
            xhr.send();
            xhr.onreadystatechange = function () {
                console.log(xhr.readyState)
                if (xhr.readyState == 4) {
                    console.log(xhr.status)
                    if (xhr.status == 200) {
                        console.log(xhr.responseText)
                        // console.log(JSON.parse(xhr.responseText))
                    } 
                    // else { console.log(xhr.status) }
                }
            }
        }
    </script>
</body>
</html>


Python 全系列/第七阶段:网页编程基础/Ajax 19382楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/IO 流技术(旧) 19384楼
JAVA 全系列/第一阶段:AI驱动的JAVA编程/飞机大战小项目训练 19385楼
Python 全系列/第七阶段:网页编程基础/JavaScript 19387楼
JAVA 全系列/第十三阶段:Spring Cloud Alibaba技术栈/Dubbo 19388楼
Python 全系列/第四阶段:函数式编程和核心特性/正则表达式 19393楼
WEB前端全系列/第一阶段:HTML5+CSS3模块/浮动与定位 19394楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/容器(旧) 19395楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637