Wednesday, 12 October 2016

javascript - Why does Medium's API prepend while(1) to the JSONP response?

just curious about https://medium.com I see that on their search page they make an automatic ajax GETrequest, I opened up my firebug(cause of curiosity) and get results as follows:


(I typed the search phrase sen to trigger GET request to https://medium.com/search/all?q=sen. Note if you opened it, it won't work since it only expects ajax request)



])}while(1);{"success":true,"payload":{"value":{"posts":[{"id":"748b78360917","versionId":"9fbac25a3c7c","creatorId":"29fed3d34b82","homeCollectionId":"e196dfdf4b5d","title":"Nous sommes des clients, pas des usagers. Et ça change tout" // MORE JSON RESPONSE FROM SERVER....


now the question is not about the JSON part, I want to know what does ])}while(1); mean in the response? What's the purpose of this?


Updated
I know that while(1) is for infinite loop, but why doing this?


Update
I read the similar question, now I know the use of 'while(1)' is to prevent json hijacking, but the '
])}while(1);' part is still confusing, why use '])}' and ''
? Isn't 'while(1)' enough?

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...