开发者

Calling ASMX Service from jQuery Client Side Code

I have a VS 2010 project locally where I have a ASMX service running locally. I created another VS 2010 project which has to consume that local ASMX service. For some reason whenever I trigger the service it gives me 500 Internal Service Error. Both applications are running on separate ports.

 $.ajax(

    {
        type: "POST",
        url: "http://localho开发者_Python百科st:22059/Mobile/HOCWebService.asmx/GetCategories",
        data: "{}",
        dataType: "json",
        contentType:"application/json",
        success: function (response) {

            alert(response); 

        }
    }

    );


Both applications are running on separate ports.

That's the problem. You are violating the same origin policy restriction. You cannot send AJAX requests to services that are not hosted on the same origin as the page containing the script (different ports => different domains).


MAKE SURE THAT YOUR ADDING THE FOLLOWING LINES OF CODE ABOVE THE WEBSERVICE CLASS

[System.Web.Script.Services.ScriptService]

AFTER ADDING THE CODE LOOK LIKE BELOW

[System.Web.Script.Services.ScriptService]
public class WSDataService : System.Web.Services.WebService

THIS ABOVE LINE OF CODE WILL ALLOW THE AJAX CLINET CALL TO CONSUME WEBSERVICE.

THEN YOUR CLIENT WILL START COSUMING

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜