<!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-跨域请求</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>
import web
urls=('/','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()
function TestAjax()
{
$.ajax({
type : "get",
async : false,
url : "ajaxHandler.ashx", //实际上访问时产生的地址为: ajax.ashx?callbackfun=jsonpCallback&id=10
data : {id : 10},
cache : false, //默认值true
dataType : "jsonp",
jsonp: "callbackfun",//传递给请求处理程序或页面的,用以获得jsonp回调函数名的参数名(默认为:callback)
jsonpCallback:"jsonpCallback",
//自定义的jsonp回调函数名称,默认为jQuery自动生成的随机函数名
//如果这里自定了jsonp的回调函数,则success函数则不起作用;否则success将起作用
success : function(json){
alert(json.message);
},
error:function(){
alert("erroe");
}
});
}
function jsonpCallback(data) //回调函数
{
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;}
}
jsonpCallback({ name:"world",message:"hello world"});
function default_jsonpCallback(data)
{
success(data); //在默认的回调方法中执行
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有