weixin_33725239 2017-01-29 20:35 采纳率: 0%
浏览 39

使用AJAX解析JSONP数据

Tomorrow I have an exam on Web Design and I can't seem to understand how to read JSONP responses with AJAX. I can do fine with JSON, as well as with JSONP as long as there is no callback function, but when the callback function has a name nothing seems to work.

I will give two examples of this:

FIRST EXAMPLE

Reading data from this link: https://openlibrary.org/api/books?bibkeys=ISBN%3A0451526538&callback=mycallback

My function:

$.ajax({
        url: "https://openlibrary.org/api/books?bibkeys=ISBN:0451526538&callback=mycallback",
        dataType: "jsonp",
        success: function(data){
            var isbn = data["ISBN:0451526538"].bib_key;
                alert(isbn);

        }
    });

SECOND EXAMPLE

And this one I can't seem to understand WHY it does/doesn't work.

My way (which doesn't work):

$.ajax({
        url: "http://www.flickr.com/services/feeds/photos_public.gne?tags=flowers&format=json#",
        dataType: "jsonp",
        success: function(data){
            alert(data.title);
    }
    });

Correct code:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
$.ajax({
            url: "http://www.flickr.com/services/feeds/photos_public.gne?tags=flowers&format=json#",
            dataType: "jsonp",
            jsonp: "jsoncallback",
            success: function(data){
                alert(data.title);
        }
        });

Can anyone PLEASE take the time to explain how I can get past the wrapper (padding) that is the callback function to access the data. Please no $.getJSONP, this is the only way I have to get this to work that will be accepted in my exam.

</div>
  • 写回答

1条回答 默认 最新

  • weixin_33717117 2017-01-29 20:39
    关注

    The jsonp parameter is jsoncallback

    http://www.flickr.com/services/feeds/photos_public.gne?tags=flowers&format=json&jsoncallback=?
    
    评论

报告相同问题?

悬赏问题

  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划