(I am aware of the fact that ajax calls must originate from the same domain, and have already gone through relevant responses)
However, I am having trouble grasping something:
We often see platforms like Facebook use the for(;;) || while(1)
pattern in their json responses:
And naturally, in order to extract and utilize the data, one must remove the for(;;)
portion and then parse it accordingly.
I've been advised (by @esailija) that:
You can't strip away the for loop unless the request originates from the same domain, that's the crux of it
Alright, this is all due to the same origin policy.
But I have a question:
Consider John incorporating this on his website (john.com
):
some content...
<script src="facebook.com/ajax/recent" type="text/javascript"></script>
some content...
Notice how it's the same URL as Facebook's (indicated by my leftmost red arrow) -
Assumption
- If he fetches the response using
<scrip>...</script>
and the result comes withoutfor(;;)
, - he'll still be unable to do anything with{"__ar:1,....}
! It would need to be padded (like jsonp) withmyCallBack({"__ar:1,....});
What I mean is:
var a=1;
{"__ar:1,....} <--- john won't be able to work with this.
var b=1;
Question :
What am I overlooking and are my assumptions accurate?