国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

json跨域調(diào)用python的方法詳解

2020-02-23 04:14:55
字體:
供稿:網(wǎng)友

本文實(shí)例講述了json跨域調(diào)用python的方法。分享給大家供大家參考,具體如下:

客戶端:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  <html xmlns="http://www.w3.org/1999/xhtml">  <head>  <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  <title>jQuery-跨域請(qǐng)求</title>  <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>  <script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>  </head>   <script type="text/javascript">  jQuery(document).ready(function(){    $.ajax({      type : "GET",      url : "http://10.13.38.43:1234/?id=10&callback=?",      dataType : "jsonp",      jsonp: 'callback',      success : function(json){          alert(json.account);        //$('#msg_box').html(json);        //return true;      }    });  });  </script>   <body>  <div id="msg_box"></div>  </body>  </html>

服務(wù)端

import weburls=('/','Index',)class Index:    def GET(self):      inputdata=web.input()      mycallbackfun=inputdata.callback      #return 'hello' +inputdata.id      return mycallbackfun+'({"account":"XX","passed":"true","error":"null"})'app = web.application(urls, globals())if __name__=='__main__':    app.run()

附:jquery跨域請(qǐng)求方法簡介

這里介紹jQuery跨域請(qǐng)求方法,并提供簡單的示例代碼供參考。

項(xiàng)目中關(guān)于ajax jsonp的使用,出現(xiàn)了問題:可以成功獲得請(qǐng)求結(jié)果,但沒有執(zhí)行success方法,總算搞定了,記錄一下。

function TestAjax(){  $.ajax({    type : "get",    async : false,    url : "ajaxHandler.ashx", //實(shí)際上訪問時(shí)產(chǎn)生的地址為: ajax.ashx?callbackfun=jsonpCallback&id=10    data : {id : 10},    cache : false, //默認(rèn)值true    dataType : "jsonp",    jsonp: "callbackfun",//傳遞給請(qǐng)求處理程序或頁面的,用以獲得jsonp回調(diào)函數(shù)名的參數(shù)名(默認(rèn)為:callback)    jsonpCallback:"jsonpCallback",      //自定義的jsonp回調(diào)函數(shù)名稱,默認(rèn)為jQuery自動(dòng)生成的隨機(jī)函數(shù)名      //如果這里自定了jsonp的回調(diào)函數(shù),則success函數(shù)則不起作用;否則success將起作用    success : function(json){      alert(json.message);    },    error:function(){      alert("erroe");    }  });}function jsonpCallback(data) //回調(diào)函數(shù){  alert(data.message); //}public class ajaxHandler : IHttpHandler{  public void ProcessRequest (HttpContext context) {    context.Response.ContentType = "text/plain";    string callbackfun = context.Request["callbackfun"];    context.Response.Write(callbackfun + "({name:/"John/", message:/"hello John/"})");    context.Response.End();  }  public bool IsReusable {get {return false;}}

ajax請(qǐng)求參數(shù)說明:

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 托里县| 安丘市| 长宁县| 名山县| 南平市| 青河县| 化隆| 宜黄县| 荆门市| 梁河县| 昌都县| 明光市| 兴安盟| 屯留县| 买车| 湘潭县| 宝清县| 岐山县| 宜阳县| 甘肃省| 万载县| 西林县| 花莲市| 南城县| 凯里市| 仲巴县| 北京市| 彭水| 金昌市| 广汉市| 黄平县| 江西省| 东乌珠穆沁旗| 泽州县| 石门县| 南涧| 三河市| 当涂县| 忻城县| 苍山县| 平江县|