weixin_33725272 2012-05-30 10:34 采纳率: 0%
浏览 31

jQuery Webservice方法调用

I'm new to Jquery and Ajax. I'm making a call to the web service and getting an XML data as output. I would like to convert the XML data into an array so that i can bind this data with the AJAX GRIDVIEW. I have posted the js code, result from the webmethod and required result. Any way to convert the XML to array. Thanks for your help.

The JS code is:

var jsonText = $.toJSON(subc);
            $.ajax(
            {
                type: "POST",
                url: "frmFeesCollection.aspx/ServerSideMethod",
                data: "{paraml: '" + jsonText + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                async: true,
                cache: false,
                success:function(result)
                {
                    var gridView = $find('<%= grdpopup.ClientID %>');
                    //Converting of XML to array here
                    var data = new Array();
                    gridView.set_dataSource(data);
                    gridView.dataBind();
                },
                error: function(err) {
                     alert('Error:' + err.responseText + '  Status: ' + err.status);
                }
           });

The result from the webservice looks like this:

<NewDataSet>  
<Table>
<SUBCAT>1</SUBCAT>
<PENDF>1</PENDF>
<PAIDM>1000.00</PAIDM>
</Table>
<Table>
<SUBCAT>1</SUBCAT>
<PENDF>1</PENDF>
<PAIDM>5000.00</PAIDM>
</Table>
<Table>
<SUBCAT>6</SUBCAT>
<PENDF>1</PENDF>
<PAIDM>1000.00</PAIDM>
</Table>
<Table>
<SUBCAT>6</SUBCAT>
<PENDF>1</PENDF>
<PAIDM>6000.00</PAIDM>
</Table>
</NewDataSet>

The required array would be something like this:

data[0] = { SUBCAT: 1, PENDF: 1,PENDM: 1000.00};
data[1] = { SUBCAT: 1, PENDF: 1,PENDM: 5000.00};
data[2] = { SUBCAT: 6, PENDF: 1,PENDM: 1000.00 };
data[3] = { SUBCAT: 1, PENDF: 1,PENDM: 6000.00};
  • 写回答

1条回答 默认 最新

  • weixin_33724659 2012-05-30 10:59
    关注

    Thanks for the effort guys. At last found this method and it works pretty fine now.

    success:function(result)
                    {
                        var gridView = $find('<%= grdpopup.ClientID %>');
                        var xmlDoc = $.parseXML(result);
                        var xml = $(xmlDoc);
                        var customers = xml.find("Table");
                        var data = new Array();
    
                        $.each(customers, function (index, value) 
                        {
                            var s =$(this).find("SUBCAT").text();
                            var p =$(this).find("PENDF").text();
                            var pm = $(this).find("PAIDM").text();
                            data[index] = { SUBCAT: s, PENDF: p,PAIDM: pm };
                        });
                        gridView.set_dataSource(data);
                        gridView.dataBind();
                        },
    
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?