Online JSONP Converter / Wrapper

I would like to get the source of the file and wrap it in JSONP .

For example, I want to get pets.txt as text from a host that I am not. I want to do this using only client-side JavaScript.

I am looking for an online service that can convert anything to JSONP.


Yql

Yahoo Query Language is one of them.

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D"http://elv1s.ru/x/pets.txt"&format=json&callback=grab

This works if the URL is not blocked using the robots.txt file. YQL has relative robots.txt file . I can not get http://userscripts.org/scripts/source/62706.user.js because it is blocked through robots.txt .

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D"http://userscripts.org/scripts/source/62706.user.js"&format=json&callback=grab

"denied": "robots.txt for the domain prohibits crawling for the URL: http://userscripts.org/scripts/source/62706.user.js "


So I'm looking for another solution.

+6
json jsonp web-services xss cross-domain
source share
4 answers

I built jsonpwrapper.com .

It is unstable and slower than YQL, but it does not care about the robots.txt file.

+5
source share

Here is another one, much faster, built on DigitalOcean and CloudFlare, using caching, etc. http://json2jsonp.com

+2
source share

Nononono. Not. Just please. not. This is not JSONP, it is javascript that executes a function with an object as a parameter that contains more javascript. Ahh!

This is JSON because it is only one object:

 { 'one': 1, 'two': 2, 'three':3 } 

This is JSONP because only one object has passed through a function; if you go to http://somesite/get_some_object?jsonp=grab , the server will return:

 grab({ 'one': 1, 'two': 2, 'three':3 }); 

This is not JSON at all. This is just Javascript:

 alert("hello"); 

And this? Javascript code stored inside a string (ouch!) Inside an object passed to a function that should evaluate the string (but it may or may not):

 grab({"body": "alert(\"Hello!\");\n"}); 

Look at all semicolons and backslashes! I get nightmares from this kind of thing. This is like a poorly written Lisp macro, because it is much more complicated than it should (and should!) Be. Instead, in the code, enter the grab function:

 function grab(message) { alert(message.body); } 

and then use JSONP to return the server:

 grab({body: "Hello!"}); 

Do not let the server decide how to launch its web page. Instead, let your web page decide how to launch the web page, and just fill in the blanks with the server.

As for the online service that does this? I don't know anything, sorry

0
source share

I'm not sure what you are trying to do here, but no one will use something like this. No one will trust your service to always execute as it should, and output the expected JavaScript code. You see that Yahoo does this because people trust Yahoo, but they will not trust you.

-2
source share

All Articles