且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从 jQuery 中的外部 URL 获取数据?

更新时间:2023-02-23 20:28:40

这里有两点:

首先,您的 URL 添加应该是 "?callback=?" 因为没有其他查询字符串,或者使用完整的 $.ajax() 使用 jsonp 数据类型调用,因此它会根据需要添加查询字符串,像这样:

First, your URL addition should be "?callback=?" since there's no other querystring, or use the full $.ajax() call with a jsonp data type, so it adds the querystring as needed, like this:

$.ajax({
  url: resturl,
  dataType: 'jsonp',
  success: function(data){
    console.log( data );
  }
});

其次,您要访问的域必须支持 JSONP.

Second, the domain you're going to has to support JSONP.