ajax data xml,How to get xml data using ajax in jquery?

可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):

问题:

I want to use ajax in jquery to get data for my page...

The problem is that the url which i call has some query strings to be sent along with it...

for example: the url which i call for getting data is:-

http://mysite.in.dataengine.aspx?t=abcde&token=h34jk3&f=xml

the data i get in response from this url can be in xml format or java script arrays(whichever i choose)

for eg...the xml wil look like this:-

and the javascript array would look like this :-

Region = new Array();

Region.push(new Array('MWEST', 'west'));

Region.push(new Array('MCENT', 'north' ));

Region.push(new Array('THAN', 'south'));

So when i get the data i want to store it in a drop down box.(using ajax)

Note I can get either xml OR javascript arrays as the returned data, not both together.

回答1:

You can make an ajax call along with parameters like this:

var paramsData = "t=abcde&token=h34jk3";

$.ajax({

type: "GET",

url: "dataengine.aspx",

data: paramsData,

dataType: "xml",

success: function(xml){

//process xml from server

}

});

回答2:

I would suggest you to get the data in JSON format, as Json comes natively to javascript and it much easliy manipulated using javascript as compared to XML. The easiest way i can see to work on your problem is to store all your data whether xml or json & put it inside a hidden div and then use jQuery to populate that data in a drop down box.

Here is an amazing jquery plugin with example that should ease your work

http://plugins.jquery.com/project/jqueryclientdb

回答3:

Just parse it. I"m not sure if this will work, but it might:

xml = ...

region = new Array();

$(xml).find('Region').each(function() {

region.push(new Array($(this).attr('SubCode'), $(this).attr('RCode'));

});

回答4:

Thanks for your help guys...but i have found the solution....Like i said...that i get in return either xml or javascript array...So..i'm using javascript arrays.. and using a function in jquery*($.getScript)* which fetches an external javascript code via ajax...Thus i am getting all my data now through ajax in jquery...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值