如何从Jquery Mobile(Android Platform)调用 asp.net 网络服务



我是一名愿意学习移动Web技术的.net开发人员。 目前我正在Android平台上工作。我发现Jquery是适合我的框架,因为我来自Web背景。到目前为止,我能够在Android上创建一个简单的Web应用程序,但是,我无法从Jquery到我的.net Web服务进行AJAX调用。我想为我的安卓网络应用程序创建一个测试环境。

1. I have ASP.NET web service running on my local computer 
    namespace JqueryMobile
    {
        [System.Web.Script.Services.ScriptService]
        public class WebService1 : System.Web.Services.WebService
        {
            [WebMethod]
            public string HelloWorld()
            {
                return "Hello World";
            }
        }
    }
my webservice URL is : http://localhost:26415/WebService1.asmx
2. My android index.html 
     $(function(){
                $.ajax({url:"localhost:26415/WebService1.asmx/HelloWorld",
                success:function(result){
                           alert(result);
                           }});
     });
    This technique fails in local environment so, how do i test it?

进行以下更改:

1.取消注释[System.Web.Script.Services.ScriptService]作为Web方法的属性

2.同时将您的网址更改为喜欢 http://localhost:1096/MySite/WebService.asmx/HelloWorld?callback

3.尝试使用 IP 地址而不是 loaclhost http://IPADDRESS:1096/MySite/WebService.asmx/HelloWorld?callback

请参阅这篇文章:使用 jquery 调用 .NET Web 服务的最佳方法是什么?

最新更新