$(document).ready(function(){ var userinfo={"name":"name","time":123456789} var _url= "http://localhost:1879/Ajax/WebService.asmx/ws?jsoncallback=?"; $.getJSON(_url,userinfo,msg); }); function msg(data) { alert(data.msg); }
[WebMethod] public void ws(string name,string time) { HttpRequest Request = HttpContext.Current.Request; string callback = Request["jsoncallback"]; HttpResponse Response = HttpContext.Current.Response; Response.Write(callback + "({msg:'this is" + name + "jsonp'})"); Response.End(); } [WebMethod] public void ws1() { HttpRequest Request = HttpContext.Current.Request; string callback = Request["jsoncallback"]; HttpResponse Response = HttpContext.Current.Response; Response.Write(callback + "({msg:111})"); Response.End(); }
uab.accessinterface._root = "http://172.20.16.109:8088/AccessInterface/rest/js/controller"; uab.accessinterface.getAllUserAbData = function(_callback){//个人联系人全量信息 var params="{/"arg/":[{/"2/":[/"user1@test.com/"],/"1/":[null]}],/"service/":[/"linkmanService/"],/"method/":[/"getAllUserAbData/"]}"; $.ajax({ dataType: "jsonp",jsonp: 'jsoncallback',async: false,url: uab.accessinterface._root,data: '_Method=GET&_JSON=' + params,error: function(){ alert("error"); },success: function(res){ _callback(res); } }); // var params="{/"arg/":[{/"2/":[/"user1@test.com/"],/"method/":[/"getAllUserAbData/"]}"; // uab.accessinterface.ajaxsend(params,_callback); }