When I include this url as a <script> in my HTML document, Chrome does not call my callback function, whereas it works perfectly for other urls returned by soundcloud's resolve api.
After a long investigation using Chrome Dev Tools, I finally found out that the javascript returned by that call fires a SyntaxError (cf the screenshot below).
How can I get my callback function to be called as usual for that file?
DevTools actually pinpoint the issue:
There is an unallowed character (\u2028) in the response. SoundCloud messed up sanitizing that. This JSONP response is invalid in all browsers.
To work around it, you can simply fetch the JSON file directly. SoundCloud CORS setup seems to allow that.
Related
While running testcafe, I could see an xhr request failing in the background and may be that is why I could not see the UI elements of the page getting loaded. I could see only one element loaded.
If I try to access the same webpage without testcafe, I could see the page elements loading normal although the xhr request is still failing in the background.
Could this failing xhr request be a reason for the page not showing all the UI elements when I do it through testcafe?
Is there a way to ignore some xhr requests like this in testcafe ?
To mock any request you can use RequestMock. For example:
const mock = RequestMock()
.onRequestTo('http://xhr-request/')
.respond('Mocked respond');
However, it may not resolve the problem. If it doesn't help, please, share a minimal working example with this template following this instruction.
(Also posted this on the eBay Dev Forums, but it has low volume and is very slow)
I'm trying to build my first call to eBay's API. I am using Postman Chrome App, but have also tried the Python Requests library, with the same problem in each.
No matter what I send, I just get back an HTTP 202 code with an empty body, instead of the XML response I am expecting. This happens with either the sandbox or the production endpoint. Doesn't matter if I use correct or incorrect credentials, or a valid or invalid API call name.
Screenshot of building the call in Postman:
Finally heard back from eBay Support.
The problem is the trailing slash on the endpoint. Any kind of trailing slash will cause a generic 202 response. Removing it fixed the problem.
I know there are several questions related to this-- but I couldn't find my answer with them. Plus I wanted a bit more clarification.
I am running a rails app locally which makes a jsonp call to a sinatra application which is being used as an API.
When I put this URL in my browser I end up getting the correct response, yet when I make this call through jQuery using $.getJSON I get a forbidden 403 Error. I understand that the $.getJSON is making a jsonp request based on the url having callback=? parameter.
I'm trying to figure out what is causing the 403 Error. Is there some default configuration on the api application that is refusing the request because the script is being requested from an included script tag?
Right now the api request return json data. I assume it's my responsibility to look at the callback parameter and construct a response that actually calls the callback...
so if url was http://myapi.com?callback=blah, then I should be returning something like:
blah({foo: 'bar'})
But I don't know exactly what the 403 is all about. If it's the api server that is returning, then what is it trying to protect against?
here is an example of what the jsonp call looks like:
$.getJSON( 'http://myapi.com?callback=?', {biz: 'buzz'})
I see posts about setting headers for cross origin concerns-- but not sure why this is needed for jsonp request.
You need to add jsonp support to your sinatra api application.
Here is one way of adding jsonp support to your sinatra app
Add rack-contrip gem to your Gemfile
gem 'rack-contrib'
Add following to your config.ru
require 'rack/contrib'
use Rack::JSONP
Restart your sinatra app and start testing jsop from javascript
if I get data from an external website in JSONP form, how do I access the http header response? I have heard this may be difficult but my experience is that everything is possible.
Nope.
This is completely impossible.
The whole point of JSONP is to bypass the same-origin policy by passing a result through executable Javascript code.
Other than JS code generated by the remote server, you cannot get any information.
My question is an extension of this one.
I am using JavaScript to post videos to the v2 YouTube API, via Plupload (HTML5 runtime). I am using OAuth2 to get authorized tokens and a CORS request to set the metadata. I am able to upload videos successfully, but the 302-coded response returned by YouTube gets lost. I am not able to retrieve the ID of the uploaded video, which would ordinarily be present as a GET parameter of the URL redirected to as part of the 302 response.
After uploading the video, how can I get the ID of the video?
It seems like xhr.getResponseHeader(location) would give it to me, but it is undefined with Plupload. Is this because Plupload is overriding the default XMLHttpRequest object and only exposing certain attributes? If I used vanilla XMLHttpRequest objects, would it work OK? Can the 302 be intercepted in all browsers?