如何在jQuery上接收DataSet(xml) [英] how to receive DataSet (xml) on jQuery

查看:77
本文介绍了如何在jQuery上接收DataSet(xml)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



i在jQuery中有这个连接到我的WebService的示例代码



发送文本,并接收文本。它的作品很棒。



Dear Friends,

i have this sample code in jQuery that connect to my WebService

sending text, and receive text. its works excellent.

<html  lang="en-US">
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
        <meta name="viewport" content="width=device-width" />
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <script type="text/javascript">

            //var WS_URI = 'http://10.0.0.5/WS_Catalog_SQL/Service1.asmx/GetItem';
            var WS_URI = 'http://10.0.0.5/WS_Catalog/Service1.asmx/GetItem';
            var MAKAT ;

            function Look() {
                MAKAT = document.getElementById("txt").value.toString();
                $.ajax({
                    ServiceCallID: 1,
                    url: WS_URI,
                    type: 'POST',
                    data: '{"Makat": "' + MAKAT + '"}',
                    contentType: 'application/json; charset=utf-8',
                    dataType: 'json',
                    success:
                        function (data, textStatus, XMLHttpRequest) {
                            //document.writeln(data.d);
                            $("#RES").text((data.d).toString());
                        },
                    error:
                  function (XMLHttpRequest, textStatus, errorThrown) {
                      alert(textStatus);
                  }
                });
            }
    </script>
</head>

<body >
          <br />
          <button onclick="Look();">Press me</button>
          <input id="txt"  value="1111"/>
          <br />
          <p id="RES">res</p>
</body>
</html>





现在我需要收到DataSet(xml),



i build WebService (在C#中)接收文本并发送DataSet



但是jQuery很有用。



我打破了我的头两天似乎无法找到解决方案....



now i need to receive DataSet (xml),

i build WebService (in C#) that receive text and sending DataSet

but the jQuery dosent work.

I broke my head for two days and can not seem to find a solution....

推荐答案

.ajax({
ServiceCallID: 1
url:WS_URI,
类型:' POST'
data:' {Makat:' + MAKAT + ' }'
contentType:' application / json; charset = utf-8'
dataType:' json'
成功:
function (data,textStatus,XMLHttpRequest){
// document.writeln(data.d);
.ajax({ ServiceCallID: 1, url: WS_URI, type: 'POST', data: '{"Makat": "' + MAKAT + '"}', contentType: 'application/json; charset=utf-8', dataType: 'json', success: function (data, textStatus, XMLHttpRequest) { //document.writeln(data.d);


#RES)。text((data.d).toString());
},
错误:
function (XMLHttpRequest,textStatus,errorThrown){
alert(textStatus);
}
});
}
< / script>
< / head >

< body>
< br />
< button onclick = Look();>按我< / 按钮 >
< ;输入id = txt value = 1111 />
< br />
< p id = RES> res < / p >
< / body >
< / html >
("#RES").text((data.d).toString()); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert(textStatus); } }); } </script> </head> <body > <br /> <button onclick="Look();">Press me</button> <input id="txt" value="1111"/> <br /> <p id="RES">res</p> </body> </html>





现在我需要收到DataSet(xml),



i build WebService (在C#中)接收文本并发送DataSet



但是jQuery很有用。



我打破了我的头两天似乎无法找到解决方案....



now i need to receive DataSet (xml),

i build WebService (in C#) that receive text and sending DataSet

but the jQuery dosent work.

I broke my head for two days and can not seem to find a solution....


在服务方面请检查

1.你必须添加

On Service side pls check
1. u have to add
[System.Web.Script.Services.ScriptService]



在Web服务类之前启用服务访问来自脚本

2.在Web服务方法之前添加此内容


before web service class to enable service access from script
2. add this before web service method

[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]



指定输出格式

3.更好的返回数据为xml而不是DataSet



在客户端




to specify the out put format
3. better return Data as xml instead of DataSet

On Client side


这篇关于如何在jQuery上接收DataSet(xml)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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