vps交流

[经验] 请教个jQuery html()的用法


目前百度的ip api返回的是

  1. {
  2.         "status": "0",
  3.         "t": "",
  4.         "set_cache_time": "",
  5.         "data": [
  6.                 {
  7.                         "ExtendedLocation": "",
  8.                         "OriginQuery": "114.114.114.114",
  9.                         "appinfo": "",
  10.                         "disp_type": 0,
  11.                         "fetchkey": "114.114.114.114",
  12.                         "location": "江苏省南京市 电信",
  13.                         "origip": "114.114.114.114",
  14.                         "origipquery": "114.114.114.114",
  15.                         "resourceid": "6006",
  16.                         "role_id": 0,
  17.                         "shareImage": 1,
  18.                         "showLikeShare": 1,
  19.                         "showlamp": "1",
  20.                         "titlecont": "IP地址查询",
  21.                         "tplt": "ip"
  22.                 }
  23.         ]
  24. }

复制代码

使用

  1. $.getScript(‘https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query=114.114.114.114&co=&resource_id=6006’,function(){
  2.    $(".city").html(.location);
  3.    });

复制代码

返回不到地址位置  

应该是

  1.    $(".city").html(.location);

复制代码

写错了  因为怎么写呢

。。。什么乱七八糟的  getScript用的也不对吧
应该是。    $.getJSON

然后返回的JSON(array)

应该是array[‘data’][‘location’]

  1. $.post(‘https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query=114.114.114.114&co=&resource_id=6006’,{},function(result){
  2.    $(".city").html(result.data[0].location);
  3.    },’json’);

复制代码

JQ都忘光了[经验]  请教个jQuery html()的用法[经验]  请教个jQuery html()的用法
4楼正解,你这$.getScript用的不对

浏览器   f12 console  运行报错大佬

小靑年 发表于 2022-2-19 11:44
浏览器   f12 console  运行报错大佬

跨域肯定报错,这种api你只能在后台请求,浏览器你肯定不行

CMBCHINA 发表于 2022-2-19 11:49
跨域肯定报错,这种api你只能在后台请求,浏览器你肯定不行

好的 谢谢

赞(0)
版权声明:本贴采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
帖子名称:《[经验] 请教个jQuery html()的用法》
帖子链接:https://bbs.toot.su/79674.html