如何使用Jquery发送GET请求?

2024-04-19 22:25:23 发布

您现在位置:Python中文网/ 问答频道 /正文

目前,我正在使用Flask和Jquery,并在控制台中获得500个内部服务器错误响应。当我用Ajax发布到flask上的url时,它难道不能被接收吗?我不明白为什么我会犯这个错误

Jquery查询

   $('.movie').click(function(){
       console.log(this);
         $(this).toggleClass('green blue').promise().done(function(){
            if ($(this).html() == "Add Movie"){
                $(this).html("Added");
            }
         });

        id = $(this).val();


        //get information from API
        $.ajax({
            url: "/profile",
            dataType: 'json',
            async: true,
            data: {id: id},
            success: function(data) {
            }
        });

Python/烧瓶

@app.route("/profile", methods = ["GET"])
def profile(id):
    print("mydata is: ", request.args['id'])
    if request.args.get:
        print("this API is reached")
        id = request.args.get['id']
        url_movie = 'https://api.themoviedb.org/3/movie/{}?api_key=78cb6b67a99ce26e6d6619c617d9c907&language=en-US'.format(id)
        r = requests.get(url_movie)
        code = r.json();
        return jsonify(code)

Error Console


Tags: apiidjsonurlgetifrequesthtml