///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Ajax请求数据 /// </summary> /// <param name="var">变量</param> /// <returns>状态</returns> public double AJAX(CVariable var) { lock (m_requests) { Dictionary <String, String> parameters = new Dictionary <String, String>(); int parametersLen = var.m_parameters.Length; AjaxRequest request = new AjaxRequest(); request.m_indicator = m_indicator; for (int i = 0; i < parametersLen; i++) { String parameter = m_indicator.GetText(var.m_parameters[i]); int idx = parameter.IndexOf(':'); String name = parameter.Substring(0, idx).ToLower(); String value = parameter.Substring(idx + 1); if (name == "type") { request.m_type = value; } else if (name == "url") { request.m_url = value; } else if (name == "datatype") { request.m_dataType = value; } else if (name == "success") { request.m_callBack = value; } } m_requests.Add(request); } return(1); }
/// <summary> /// Ajax处理类 /// </summary> public static void AjaxHandle() { while (true) { AjaxRequest request = null; if (m_requests != null) { lock (m_requests) { int requestsSize = m_requests.Count; if (requestsSize > 0) { request = m_requests[requestsSize - 1]; m_requests.RemoveAt(requestsSize - 1); } } } if (request != null) { String resStr = ""; String lowerType = request.m_type.ToLower(); if (lowerType == "get") { resStr = HttpGetService.Get(request.m_url); } else if (lowerType == "post") { resStr = HttpPostService.Post(request.m_url); } if (m_listener != null) { m_listener.Invoke(new AjaxResponse(request.m_indicator, request.m_type, request.m_url, request.m_dataType, request.m_callBack, resStr)); } else { request.m_indicator.CallFunction(request.m_callBack + "('" + resStr + "');"); } } Thread.Sleep(1); } }