将ajax结果附加到div [英] append ajax result to div

查看:72
本文介绍了将ajax结果附加到div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对IMDb API进行ajax调用,以获取The Shawshank Redemption的电影数据。我希望将这些数据放入我创建的div中。

I'm making an ajax call to the IMDb API to get the movie data for 'The Shawshank Redemption'. I want this data to be put in the div I created.

<div id="movie-data"></div>

目前我的js代码:

$(init);


function init() {

    $.ajax({
        dataType: "json",
        url: "http://www.omdbapi.com/?i=tt0111161",
        success: function (data) {
            console.log(data);
            $("#movie-data").append(data);
        }
    });

它没有给出任何回复。但是,我可以在控制台中看到数据。当我附加< p>测试< / p> 而不是数据时,它会将测试返回到屏幕。

It doesn't give any response. However, I can see the data in my console. When I append <p>Test</p> instead of data it does return 'Test' to the screen.

推荐答案

这就是我的所作所为。它似乎现在正在运作。感谢大家。

This is what I did. It seems to be working now. Thanks everyone.

 $.ajax({
        dataType: "json",
        url: "http://www.omdbapi.com/?i=tt0111161",
        success: function (data) {
            console.log(data);
            $("#movie-data").append(JSON.stringify(data));

这篇关于将ajax结果附加到div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆