Json, Jsonp

Source: Internet
Author: User

Sonp is simply a hack to allow web apps to retrieve data across domains. It could is said that it violates the same Origin Policy (SOP).

The the-it works is by using Javascript to insert a "script" element into your page. Therefore, you need a callback function. If you didn ' t

There is one, your Javascript would have no-to access the JSON object. But by using JSONP, your Javascript code can call the callback

function. So you must specify the callback name. So your function might look like this:

private static String getJSONPObject(String callback, String s) throws JSONException {    return callback + "(" + new JSONObject(s) + ")";}


JSON format:
{    "message": "Get Succeeded",    "state": "1",    "result": {"name": "Workgroup 1", "id": 1, "description": "11"}}
JSONP format:
Callback ({    "message": "Get Succeeded",    "state": "1",    "result": {"name": "Workgroup 1", "id": 1, "description": "11"}})

Jquery插件:
https://github.com/congmo/jquery-jsonp

Json, Jsonp

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.