簡體   English   中英

如何使用jQuery發送GET請求?

[英]how do I send a GET request with Jquery?

目前,我正在使用Flask和Jquery,並在控制台中收到500 Internal Server Error響應。 當我用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)

錯誤控制台

500是服務器錯誤。 僅在服務器端執行請求有問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM