weixin_33701294 2017-10-28 10:35 采纳率: 0%
浏览 104

jQuery ajax获取json数据

how to get image url from "https://api.qwant.com/api/search/images?count=10&offset=1&q=cars" api using jquery. i'm unable to do it. bellow i've attached my code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$.ajax({
    url:"https://api.qwant.com/api/search/images?count=10&offset=1&q=cars",
    type:"GET",
    crossDomain : true,
    async: false,
    dataType: "jsonp",
    jsonpCallback: "myJsonMethod",
    success: function(json) {
       $.parseJson(json)
    },
    error: function(e) {
       console.log(e);
    }
});

function myJsonMethod(response)
{
    console.log(response);
}
</script>
  • 写回答

2条回答 默认 最新

  • MAO-EYE 2017-10-28 11:00
    关注

    Try this

    $.ajax({
        url:"https://api.qwant.com/api/search/images?count=10&offset=1&q=cars",
        type:"GET",
        crossDomain : true,
        async: false,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        jsonpCallback: "myJsonMethod",
        success: function(json) {
           $.parseJson(json)
        },
        error: function(e) {
           console.log(e);
        }
    });
    

    This is a CORS thing, so you can server all this up from a web server, like http-server, and I think certain browsers like Firefox allow this to occur locally.

    There are some flags with Chrome that'd allow it to work locally like this too, I believe.

    Cheers

    评论

报告相同问题?

悬赏问题

  • ¥15 luckysheet
  • ¥25 关于##爬虫##的问题,如何解决?:
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题