json - jQuery.getJSON causes "Uncaught SyntaxError: Unexpected token :" for youtube oembed -
here i'm trying do:
$.getjson('http://www.youtube.com/oembed?url=http://www.youtube.com/watch%3fv%3db-m6jdyrfvk&callback=?', function(data) { console.log(data) }); when curling url response:
{ "provider_url": "http:\/\/www.youtube.com\/", "title": "coder girl", "html": "\u003cobject width=\"425\" height=\"344\"\u003e\u003cparam name=\"movie\" value=\"http:\/\/www.youtube.com\/v\/b-m6jdyrfvk?version=3\"\u003e\u003c\/param\u003e\u003cparam name=\"allowfullscreen\" value=\"true\"\u003e\u003c\/param\u003e\u003cparam name=\"allowscriptaccess\" value=\"always\"\u003e\u003c\/param\u003e\u003cembed src=\"http:\/\/www.youtube.com\/v\/b-m6jdyrfvk?version=3\" type=\"application\/x-shockwave-flash\" width=\"425\" height=\"344\" allowscriptaccess=\"always\" allowfullscreen=\"true\"\u003e\u003c\/embed\u003e\u003c\/object\u003e", "author_name": "dalechase", "height": 344, "thumbnail_width": 480, "width": 425, "version": "1.0", "author_url": "http:\/\/www.youtube.com\/user\/dalechase", "provider_name": "youtube", "thumbnail_url": "http:\/\/i3.ytimg.com\/vi\/b-m6jdyrfvk\/hqdefault.jpg", "type": "video", "thumbnail_height": 360 } but when try execute above code, uncaught syntaxerror: unexpected token : (chrome). looks problem might have escaping of forward slashes, or maybe jquery sending jsonp request, response pure json.
has else run problem?
youtube (as of time of answer) oembed doesn't support jsonp requests, you're getting correct...but it's not need. need jsonp calls this:
functionname({ "provider_url": "http:\/\/www.youtube.com\/", "title": "coder girl", "html": "\u003cobject width=\"425\" height=\"344\"\u003e\u003cparam name=\"movie\" value=\"http:\/\/www.youtube.com\/v\/b-m6jdyrfvk?version=3\"\u003e\u003c\/param\u003e\u003cparam name=\"allowfullscreen\" value=\"true\"\u003e\u003c\/param\u003e\u003cparam name=\"allowscriptaccess\" value=\"always\"\u003e\u003c\/param\u003e\u003cembed src=\"http:\/\/www.youtube.com\/v\/b-m6jdyrfvk?version=3\" type=\"application\/x-shockwave-flash\" width=\"425\" height=\"344\" allowscriptaccess=\"always\" allowfullscreen=\"true\"\u003e\u003c\/embed\u003e\u003c\/object\u003e", "author_name": "dalechase", "height": 344, "thumbnail_width": 480, "width": 425, "version": "1.0", "author_url": "http:\/\/www.youtube.com\/user\/dalechase", "provider_name": "youtube", "thumbnail_url": "http:\/\/i3.ytimg.com\/vi\/b-m6jdyrfvk\/hqdefault.jpg", "type": "video", "thumbnail_height": 360 }); ...since comes not valid javascript (by itself, , that's is), , that's how jsonp works, response needs executable javascript.
you can same error plopping code straight in page in <script> block (see demo here).
i'm not sure exactly you're trying do, if you're after embedding piece, recommend plugin jquery-oembed that. if you're after data...you'll need on server process json, data server after that.
Comments
Post a Comment