views:

271

answers:

1

When I'm accessing web service from jquery, I'm getting the 403 forbidden error.. I published and created in the virtual directory too. Wat's the cause of this error and how to rectify it? I've added the webservice in the same solution.. This is my following code..

$(document).ready(function() {   
         $("#sayHelloButton").click(function(event){   
             $.ajax({   
                 type: "POST",
                 url: "App_Code/DummyWebService.asmx/HelloToYou",   
                 data: "{'name': '" + $('#name').val() + "'}",   
                 contentType: "application/json; charset=utf-8",   
                 dataType: "json",   
                 success: function(msg) {   
                     AjaxSucceeded(msg);   
                 },   
                 error: AjaxFailed   
             });   
         });   
     });   
          function AjaxSucceeded(result) {   
              alert(result.d);   
          }   
          function AjaxFailed(result) {   
              alert(result.status + ' ' + result.statusText);
          }

I suppose using that url path for webservice is wrong.. I used the path 'DummyWebservice.asmx'. There I'm getting the 500 internal server error.

+2  A: 

IIS and the dev server prevent access to your App_Code folder. This is where you should store your class files but your asmx needs to be in a publicly visible location.

Move your asmx into the root of your site but leave your asmx.cs in the App_Code so it is compiled.

Then obviously change the path in your JavaScript and give it a try.

Greg B