How do I know if a server has JSONP turned on?

后端 未结 3 1777
春和景丽
春和景丽 2020-12-06 02:21

How do I know if a server has JSONP turned on? It is not my server, but I try to access some information from the rendered html.

Thanks in advance.

相关标签:
3条回答
  • 2020-12-06 02:35

    For most servers, you can make a request in your browser to whatever JSON page/service they have and just add a callback function in the URL, for example if it's this:

    http://example.com/getJson?var=something
    

    Add the callback query parameter, like this:

    http://example.com/getJson?var=something&callback=myFunction
    

    The response instead of this (it will look like this if it doesn't support JSONP):

    { "thing": "value" .... }
    

    Should look like this (again, if it supports JSONP):

    myFunction({ "thing": "value" .... });
    
    0 讨论(0)
  • 2020-12-06 02:39

    The server has JSONP turned on if you can add callback to the URL:

    http://example.com/api/get_info.js?callback=myfunc
    

    and the server responds with your requested information in JSON-format, wrapped with your callback:

    myfunc({
        /* json formatted data goes here */
    });
    
    0 讨论(0)
  • 2020-12-06 02:43

    You read the API documentation for the web service that you are trying to access.

    0 讨论(0)
提交回复
热议问题