Jerry
Jerry

Reputation: 6577

How to resolve web service url in JQuery Ajax?

I have a ASP.Net project(not website). I have added the JQuery autocomplete widget to my master page and use the widget in MyPage.aspx.

In the .master I use something like this:

$.ajax({
                    url: "/MyService.asmx/MySearchMethod",
                    data: "{ 'param1': '" + request.term + "' }",
                    dataType: "json",
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    dataFilter: function (data) { return data; },

The MyService.asmx points to:

  CodeBehind="~/App_Code/MyServiceMethods.cs" Class="MySearchMethod"

Everything works fine while in VS2010 development.

The problem is when I deploy the app to a test web server, I get the below error:

System.InvalidOperationException: No web service found at: /MyService.asmx

How can I reference my web service in the ajax url: so that the address can be resolved when the app is deployed?

Upvotes: 0

Views: 4025

Answers (1)

Tomer Klein
Tomer Klein

Reputation: 446

try to use it as follows:

$.ajax({
                    url: "MyService.asmx/MySearchMethod",
                    data: "{ 'param1': '" + request.term + "' }",
                    dataType: "json",
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    dataFilter: function (data) { return data; },

or:

$.ajax({
                    url: "~/MyService.asmx/MySearchMethod",
                    data: "{ 'param1': '" + request.term + "' }",
                    dataType: "json",
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    dataFilter: function (data) { return data; },

Upvotes: 1

Related Questions