jQuery Ajax 调用WebService出错解决方法
开发环境:
framework2.0,System.Web.Extensions.dll(版本号:1.0.61025.0)
ajax code:
$.ajax({ type: "POST", url: webURL, data: jsonParam, contentType: "application/json; charset=utf-8", dataType: "json", success: function(data) { //callback(); }, error: function(msg) { alert(msg.ResponseText); } })
webservice
[WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] [ScriptService] public class WebService1 : System.Web.Services.WebService { [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public string HelloWorld(string pageIndex, string pageSize) { //BLL code } }
如果这样的话前台是不能访问service的,你必须在config文件里加入下面一段代码:
<httpHandlers> <add verb="*" path="*.asmx" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions,Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35"/> </httpHandlers>