zoukankan      html  css  js  c++  java
  • Json 、 Jsonp

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

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

    have one, your Javascript would have no way 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格式:
    {
        "message":"获取成功",
        "state":"1",
        "result":{"name":"工作组1","id":1,"description":"11"}
    }
    jsonp格式:
    callback({
        "message":"获取成功",
        "state":"1",
        "result":{"name":"工作组1","id":1,"description":"11"}
    })

    Jquery插件:
    https://github.com/congmo/jquery-jsonp
  • 相关阅读:
    N皇后问题
    SDNU1349.快速幂入门
    SDNU1522.陆历川学数学
    埃氏筛
    快速幂
    string函数
    Golang介绍以及安装
    Promise解决回调地狱(多层调用问题)
    JavaScript动画相关
    ES6简单语法
  • 原文地址:https://www.cnblogs.com/yuyutianxia/p/5466699.html
Copyright © 2011-2022 走看看