HTML:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script> $(function() { $('#btn').click(function() { $.ajax({ url: "http://liangjiang:888/Mobile/test", //?callback=fun jsonpCallback: 'fun', type: "get", dataType: 'jsonp', async: true, cache: false, success: function(data) { //也可以在此处理回调 debugger; }, error: function(x, y, z) { //debugger; }, complete: function(x, y, z) { //debugger; } }); }) }) function fun(data) { debugger; //也可以在此处理回调 } </script> </head> <body> <input type="button" name="btn" id="btn" value="开始请求" /> </body> </html>
C#:
//这是MVC控制器下的Acction示例,ASP.NET请按此思维自行类推
public string test(string Name, string IDCard) { var json = new { name = Emodel.MotherName, zuer = HearingScreeModel.STEOAELEars, youer = HearingScreeModel.STEOAEREars, home = Emodel.BirthHospital, }; var obj = Newtonsoft.Json.JsonConvert.SerializeObject(new { r = 1, i = "", d = json }); return (Request["callback"] + "("+ obj + ")"); }
本博客所有内容均对所有人无条件共享,欢迎学习或转载,同时也希望您也加入我们一起推动知识界的共享。
www.mccn.pub