开发者

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:-

<root version="1.0">  
    <Regions>
    <Region SubCode="MWEST" RCode="west"/>  
    <Region SubCode="MCENT" RCode="north"/>  
    <Region SubCode="THAN" RCode="south"/>  
    </Regions>开发者_运维知识库;  
</root>

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.


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
    }
});


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


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'));
});


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜