- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试连接到 RubyGems API ,但是当我尝试获取 JSON 时,出现了一个错误。
Uncaught SyntaxError: Unexpected token :
我在其他问题和帖子中看到过这个错误,但没有一个对我有用。
这是我的 $.getJSON() 函数
.getJSON("http://rubygems.org/api/v1/gems/rails.json?jsoncallback=?", function(data) {
...function stuff....
});
这是我应该收到的 JSON:
{"dependencies":{"runtime":[{"name":"actionmailer","requirements":"= 3.0.9"},{"name":"actionpack","requirements":"= 3.0.9"},{"name":"activerecord","requirements":"= 3.0.9"},{"name":"activeresource","requirements":"= 3.0.9"},{"name":"activesupport","requirements":"= 3.0.9"},{"name":"bundler","requirements":"~> 1.0"},{"name":"railties","requirements":"= 3.0.9"}],"development":[]},"name":"rails","downloads":4474748,"info":"Ruby on Rails is a full-stack web framework optimized for programmer happiness and sustainable productivity. It encourages beautiful code by favoring convention over configuration.","version_downloads":93309,"version":"3.0.9","homepage_uri":"http://www.rubyonrails.org","bug_tracker_uri":"http://rails.lighthouseapp.com/projects/8994-ruby-on-rails","source_code_uri":"http://github.com/rails/rails","gem_uri":"http://rubygems.org/gems/rails-3.0.9.gem","project_uri":"http://rubygems.org/gems/rails","authors":"David Heinemeier Hansson","mailing_list_uri":"http://groups.google.com/group/rubyonrails-talk","documentation_uri":"http://api.rubyonrails.org","wiki_uri":"http://wiki.rubyonrails.org"}
谁能帮帮我:)
最佳答案
是什么让您认为 rubygems.org 完全支持 JSONP?我在 the documentation 中没有看到任何关于 JSONP 的提及当我这样做时:
lynx -dump -source 'http://rubygems.org/api/v1/gems/rails.json?jsoncallback=x'
我从
lynx -dump -source 'http://rubygems.org/api/v1/gems/rails.json'
两者之间的唯一区别是 downloads
和 version_downloads
发生了变化,但这是意料之中的。
当您在查询字符串中使用 jsoncallback=?
时,jQuery 将设置一个回调函数并假设远程 URL 将发回调用指定函数的 JavaScript(不是 JSON!)。因此,如果远程服务在您期望 JavaScript 时发回 JSON,浏览器最终将尝试将 JSON 解释为 JavaScript 并感到不安,因为
{"dependencies":{"runtime":[{"name":"action ...
不是有效的 JavaScript 语句。这听起来与您看到的错误完全一样。
我认为您将不得不通过自己的服务器代理 JSON。你需要在你的服务器上有一个 Controller ,它可以调用以获取 JSON,然后简单地将它回显给你的 JavaScript,这将解决你的客户端缺乏 JSONP 支持和跨域问题。
关于javascript - Jquery getJSON 未捕获语法错误 : Unexpected token : error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6590608/
我正在尝试获取客户端的 IP 地址和 GPS 坐标。使用 jQuery,我有这个: $.getJSON("http://jsonip.appspot.com/", function(data) {
这个问题已经有答案了: Why does JQuery.getJSON() have a success and a done function? (2 个回答) 已关闭 6 年前。 我想知道这两个代
所以首先,是的,我知道有几个答案,但没有一个能够解决我的问题。首先我将展示我的代码HTML: Shop
假设我有以下 JavaScript: (function($) { $.getJSON(url, function(data) { $.each(data.rows, function(i
是否可以使用 jQuery 在另一个 getJSON 请求中使用 getJSON 请求? 像这样: // Population the Requests List // jQuery AJAX cal
我有以下代码,该代码已针对此问题进行了简化。基本上我有一个循环,在每次迭代中调用 jquery getJSON 函数,调用 API 端点来获取一些天气数据。问题是,当 getJSON 请求被触发时,我
我有一个使用 getJSON 的函数,但它没有像我预期的那样工作。 function balbla(name, param) { $.getJSON("/blabla.json?nam
我有一段代码,例如: $.getJSON("http://mysite.org/polls/saveLanguageTest?url=" + escape(window.location.href)
我正在使用jquery.getJSON() ,但我不知道如何进行错误处理。这些是我需要处理的一些情况。 1)如果返回的数据为null怎么办? 2)如果返回的数据不能解析json怎么办? 3) 如果返回
我正在通过参与一个测试项目(包括 SubSonic 和 jQuery)来学习 asp.net mvc。 我遇到的问题是,每次我想要返回的不仅仅是简单字符串(例如 Json 对象)时,我都会遇到困难,因
执行跨域查询,如果运行的URL不可用(404),如何执行某个功能?我尝试这样的事情: $.getJSON({ url:'example.php?callback=?', statusCode: { 4
我在 jQuery 中搜索了相关主题,但没有找到任何方法来解决我的问题。 $(document).ready(function(){ $("#inputForm").submit(functi
当调用 yahoo Web 服务 (http://boss.yahooapis.com/ysearch) 返回数据集时,是否可以设置超时并在超时后退出例程? jQuery.getJSON("http:
我正在使用 jQuery getJSON() 函数。这个函数获取数据没有问题。但有时等待,等待等待......我的加载栏在页面中心显示加载加载。 所以 jQuery ajax() 函数有一个超时变量。
我有一个 html 代码: asd $('button').click( function() { $.getJSON('/schedule/test/', function
目标:我所追求的是每次在数据库中添加某些内容时(在 $.ajax 到 Submit_to_db.php 之后),从数据库获取数据并刷新 main.php(通过 draw_polygon 更明显)。 所
我已经阅读了文档并用谷歌搜索了此内容,但没有看到问题所在。我正在尝试从本地 json 文件获取一些数据。我已在 JSONLint 验证了响应数据 代码 $(document).ready(functi
我在json.getJSON方法上遇到麻烦。这是我当前的代码: var jqxhr = $.getJSON("http://127.0.0.1:5002?callback=?", function()
我需要进行跨域请求,并且 getJSON 有问题。 $.getJSON("http://usr:pwd@10.0.1.xx/cgi-bin/remote/request.cgi?m=json&r=gr
这个问题已经有答案了: How do I return the response from an asynchronous call? (42 个回答) 已关闭 8 年前。 这是我的问题 我有一个充满
我是一名优秀的程序员,十分优秀!