Ajax Webservice call

spud1966

New Member
I have the below code in my ASPX page to get some data from a webservice. I cannot use WCF so I am using the ASMX and .Net 3.5. However, what I get back is the yellow ASP.net error page talking about setting the web.config error tag to OFF. If I call my method from code behind and response.write it to the page I get a Json string that I have viewed in JSON Viewer and it parses fine. My issue here is the URL format. What am I doing wrong here. Every example I have found uses the webservice.asmx/Method format. I have also added the protocols to my web.config\[code\]<protocols> <add name="HttpGet"/> <add name="HttpPost"/></protocols>\[/code\]Page Script: \[code\] $.ajax({ type: 'GET', contentType: "application/json; charset=utf-8", url: 'http://myserver/mywebservice.asmx/MyMethod', dataType: 'jsondata', success: function (msg) { var table = "<table><tr><th>ID</th><th>Title</th></tr>" for (var i = 0; i <= msg.length - 1; i++) { var row = "<tr>"; row += "<td>" + msg.ID + "</td>"; row += "<td>" + msg.Title + "</td>"; row += "</tr>"; table += row; } table += "</table>"; $("#myDiv").html(table); }, complete: function () { alert("complete"); } });\[/code\]Webservice:\[code\] <WebMethod(), ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=True)> _Public Function MyMethod() As String 'removed for shorter postEnd Function\[/code\]
 
Back
Top