标签:
直接上代码:
JavaScript:
1 /** 2 * 贵金属、外汇及原油的价格 3 */ 4 function getDDE(code,id) { 5 $.ajax({ 6 type: "POST", 7 url: "http://market.gs9999.com/tools/submit_ajax.ashx?action=metal_realtime&t=" + Math.random(), 8 timeout: 20000, 9 data: { 10 code: code 11 }, 12 dataType: "json", 13 success: function (data) { 14 alert(data); 15 } 16 }); 17 }
submit_ajax.ashx:
1 /// <summary> 2 /// AJAX提交处理 3 /// </summary> 4 public class submit_ajax : IHttpHandler, IRequiresSessionState 5 { 6 public void ProcessRequest(HttpContext context) 7 { 8 //允许跨站,指定域名:http://www.gs9999.com,若值为"*",则允许所有的网站访问。 9 context.Response.AddHeader("Access-Control-Allow-Origin", "http://www.gs9999.com"); 10 11 //取得处事类型 12 string action = GsRequest.GetQueryString("action"); 13 14 switch (action) 15 { 16 case "metal_realtime": //贵金属实时 17 metal_realtime(context); 18 break; 19 default: 20 context.Response.Write("{\"msg\": 0, \"msgbox\": \"参数传输有误!\"}"); 21 break; 22 } 23 } 24 25 public bool IsReusable 26 { 27 get 28 { 29 return false; 30 } 31 } 32 }
标签:
原文地址:http://www.cnblogs.com/zengb/p/4306998.html