How to make a jsonp call to an api using jquery

前端 未结 3 1528
梦如初夏
梦如初夏 2021-01-13 15:27

I am new to programming in general and i am having trouble getting the data into my web app when i make a call to the moviedb.org api. I am using jquery and i have read all

3条回答
  •  无人及你
    2021-01-13 15:51

    This function "post" call the server

    $.post("http://api.themoviedb.org/2.1/Movie.getImages/en/json/ed7e2e092ca896037ce13d2bf11a08f1/550&callback=?", 
       function(data){ 
        //After the server code run, this code is executed with the 
        //information of the response into the parameter 'data'
        $.each(data, function(i,item){ 
        $("").attr("src", item.image).appendTo("#images");
        });
       }, 
     json");
    

    As you can see, I put the same "each" iteration function. I do not know if you're doing it correctly, because I don't execute this code. But I strongly recommend that you try execute the code into the function(data)... with an alert(...) as I show below:

    $.post("http://api.themoviedb.org/2.1/Movie.getImages/en/json/ed7e2e092ca896037ce13d2bf11a08f1/550&callback=?", 
       function(data){
        alert(data);
       }, 
    "json");
    

    With this do you really know what s "data" vale.

    I hope you have been helpful.

提交回复
热议问题