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

华锦
2023-12-01

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

问题:

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

 类似资料:

相关阅读

相关文章

相关问答