zoukankan      html  css  js  c++  java
  • about jsonp introduce

    first we use jquery build a jsonp request like bellows

            _pjs$.getJSON("http://localhost:8000/xhr_test2?x=1&callback=?", function(data) {
                //alert("Symbol: " + data.symbol + ", Price: " + data.price);
                console.log("DDDDDDDDDDDDDDDDD");
            });

    jquery will send the request as follows:

    http://localhost:8000/xhr_test2?x=1&callback=jQuery16402700680344839699_1336379810409&_=1336379811771

    yes,jquery will replace the callback after ? symbols with a auto generatered string

    in our server-back we need capture the callback parameter and wrapit with callback(data) outside the return data

    def xhr_test2(request):
        callback=request.GET.get("callback")
        print callback
        logging.debug(callback)
        if request.is_ajax():
            message = "%s({'symbol': 'IBMajax', 'price': 91.42});"%callback
            print message
            logging.debug(message)
        else:
            message = "{'symbol': 'IBM', 'price': 91.42}"
            message = "%s({'symbol': 'IBMajax', 'price': 91.42});"%callback
            print message
            logging.debug(message)

    reference:

    http://www.ibm.com/developerworks/cn/web/wa-aj-jsonp1/

    use jsonp we can solve cross-origin problem

  • 相关阅读:
    request.getRealPath的替代方法
    springmvc文件上传示例
    查询表部分列
    表名作为变量的应用
    行转列
    老男孩python学习第三天作业
    老男孩python学习第四天作业
    老男孩python学习第二天思维导图
    老男孩python学习第三天思维导图
    老男孩python学习第五天思维导图
  • 原文地址:https://www.cnblogs.com/lexus/p/2487634.html
Copyright © 2011-2022 走看看