我正在尝试从Web服务获取json数据。使用ASP.NET Ajax [英] I'm trying to get json data from a web service. using ASP.NET Ajax

查看:78
本文介绍了我正在尝试从Web服务获取json数据。使用ASP.NET Ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

网络服务代码... Service.asmx



Web Service code... Service.asmx

[WebMethod]
   public string HelloWorld() {
       string log = "Hello World";
       JavaScriptSerializer jss = new JavaScriptSerializer();
       string json = jss.Serialize(log);
       return json;
   }









我想要上网服务数据......通过ajax。







where I want to get web service data... through ajax.

<script type="text/javascript" src="

http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<script type="text/javascript">
     $(document).ready(function(){

            $.ajax({
                type: "POST",
                url: "Service.asmx/HelloWorld",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {
                    alert(msg.d);
                },
                error: function(e) {
                    alert("WebSerivce unreachable");
                }
            });
        });
    </script>







但我得到错误获取网络服务数据。




but I am getting error get web service data.

推荐答案

(文件) .ready(function(){
(document).ready(function(){


.ajax({
type:POST,
url:Service.asmx / HelloWorld,
data:{},
contentType:application / json; charset = utf-8,
dataType:json,
success:function(msg){
alert(msg.d);
},
错误:function(e){
alert(WebSerivce unreachable);
}
});
});
< / script >
.ajax({ type: "POST", url: "Service.asmx/HelloWorld", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { alert(msg.d); }, error: function(e) { alert("WebSerivce unreachable"); } }); }); </script>







但我收到错误获取网络服务数据。




but I am getting error get web service data.


http://stackoverflow.com/questions/211348/ how to to-let-an-asmx-file-output-json [ ^ ]



您应该要求服务返回json数据
http://stackoverflow.com/questions/211348/how-to-let-an-asmx-file-output-json[^]

you should ask service to return json data


这篇关于我正在尝试从Web服务获取json数据。使用ASP.NET Ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆