我正在使用 Framey API 进行视频录制。当我发出请求时,我得到了我期望的 json 响应,但出现了错误:
Uncaught SyntaxError: Unexpected token :
这是javascript
var url = "http://framey.com/api/videos/ba9bd910-549d-012e-32f4-549a20bdfc52?
api_key=7VNKGLJZLKSASZ0FXN2TVSZQU&signature=41B08D68E0A4AC2DD91107BBD6AD08B8&time_stamp=1304447242";
$("button").click(function() {
$.ajax({
url: url,
dataType: 'json',
crossDomain: true
}).done(function() {
$(".video").html("here it is babyF!");
});
});
该网址只是 Framey 网站的示例网址,我不知道它是否有效。通过阅读这个问题Uncaught SyntaxError: Unexpected token :,我认为我可能遇到了同样的问题。该问题的选定答案是
对于可能有同样问题的人来说,仅供参考——我只需要让我的服务器将 JSON 作为 application/json 发回,默认的 jQuery 处理程序就可以正常工作。
我认为我无法影响 Framey 向我发回数据的方式,所以我不确定如何解决这个问题。也许它是别的东西?提前致谢,如果您需要更多信息,请告诉我。
=========编辑============
这是 Framey 的回复,它给了我错误:
{"success":true,"video":{"name":"6d235a90-7b4b-012f-f97e-12313d297e67","filesize":1335504,"duration":20.48,"state":"uploaded","views":1,"data":{},"flv_url":"http://framey.com/videos/source/6d235a90-7b4b-012f-f97e-12313d297e67.flv","mp4_url":"http://framey.com/videos/source/6d235a90-7b4b-012f-f97e-12313d297e67.mp4","large_thumbnail_url":"http://framey.com/thumbnails/large/6d235a90-7b4b-012f-f97e-12313d297e67.jpg","medium_thumbnail_url":"http://framey.com/thumbnails/medium/6d235a90-7b4b-012f-f97e-12313d297e67.jpg","small_thumbnail_url":"http://framey.com/thumbnails/small/6d235a90-7b4b-012f-f97e-12313d297e67.jpg"}}
我认为这是关于 Framey 将“application/javascript”放在应该说“application/json”的地方
============ 编辑2 =================
这是响应的标题,我通过查看 Chrome 中控制台的“网络”部分得到了这些标题。
Request URL:http://www.framey.com/api/videos/32a7aaf0-7c3a-012f-37bd-12313b093125?api_key=00000000&signature=624643a3481b2a2c2bdb6c7cc29c506e&time_stamp=1536494436&callback=jQuery17202607689620926976_1336594235235&_=1336594483714
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Cookie:__utma=229279307.404664337.1336485291.1336573199.1336589854.6; __utmc=229279307; __utmz=229279307.1336485291.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _video-recorder_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRiIlN2VjODBiYWM1NDk2MDlkYTg2ZTY0NzEzNDA5Zjg3ZGJJIhBfY3NyZl90b2tlbgY7AEZJIjE4aW5KVktxakhyVTRvVGY0RXZlNkVkMU9lV0p1NUEzR01rVzlNK1hRWEJ3PQY7AEY%3D--b9a5f6cf08d7539d2bf9ebebc83ce96b0d070615
Host:www.framey.com
Referer:http://localhost:3000/questions/1
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19
Query String Parametersview URL encoded
api_key:000000000000
signature:624643a3481b2a2c2bdb6c7cc29c506e
time_stamp:1536494436
callback:jQuery17202607689620926976_1336594235235
_:1336594483714
Response Headersview source
Cache-Control:max-age=0, private, must-revalidate
Connection:keep-alive
Content-Length:709
Content-Type:text/javascript; charset=utf-8
ETag:"5e8393861da01fa2effd911365a90e6b"
Server:nginx/1.0.10 + Phusion Passenger 3.0.11 (mod_rails/mod_rack)
Set-Cookie:_video-recorder_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRiIlN2VjODBiYWM1NDk2MDlkYTg2ZTY0NzEzNDA5Zjg3ZGJJIhBfY3NyZl90b2tlbgY7AEZJIjE4aW5KVktxakhyVTRvVGY0RXZlNkVkMU9lV0p1NUEzR01rVzlNK1hRWEJ3PQY7AEY%3D--b9a5f6cf08d7539d2bf9ebebc83ce96b0d070615; path=/; HttpOnly
Status:200
X-Powered-By:Phusion Passenger (mod_rails/mod_rack) 3.0.11
X-Runtime:0.060476
X-UA-Compatible:IE=Edge,chrome=1
特别感兴趣的是内容类型标头:它是 text/javascript。