English 中文(简体)
AJAX 装载XML的图像
原标题:AJAX to load XML with images

我是美国宇宙航空研究开发机构世界的新鲜人物,因此,请原谅。 我有一份XML文件。

<juices>
<smoothie id="SY4301">
    <name>Strawberry Yumghurt</name>
    <price currency="GBP">
        <perunit type="wholesale">1.23</perunit>
        <perunit type="RRP">1.89</perunit>
        <percrate>28.50</percrate>
    </price>
    <description>Velvety yoghurt smoothie made with fresh strawberry and rasperries.</description>
    <ingredients>
        <ingredient image="/images/strawberry.jpg" quantity="9">Strawberries</ingredient>
        <ingredient image="/images/Raspberry.jpg" quantity="4">Raspberries</ingredient>
        <ingredient image="/images/yoghurt.jpg"quantity="200ml">Greek Yoghurt</ingredient>
        <ingredient image="/images/honey.jpg" quantity="30ml">Runny Honey</ingredient>
        <ingredient image="/images/milk.jpg"quantity="40ml">Semi-skimmed Milk</ingredient>
    </ingredients>
    <nutrition per="100ml">
        <kcal unit="cal">140</kcal>
        <kjoules unit="KJ">442</kjoules>
        <carbohydrate unit="g">27.9</carbohydrate>
        <protein unit="g">1.4</protein>
        <fat unit="g">8.4</fat>
        <fibre unit="g">2.8</fibre>
    </nutrition>
    <imageloc>http://www5.bbk.ac.uk/~akaufm01/jvfma/Images/Products/morning_kick.jpg</imageloc>
</smoothie>
</juices>

I have an XSL document that is loading everything but the ingredients on page load, but what I want to achieve is that on clicking (link or button, I don t mind which), replace the contents of one of the divs (#description) with a list of the ingredients accompanied by its image, the location of which is stored in the image attribute.

我已经看过一些教导师,他们建议利用 j子来实现这一目标,但我 have不敢工作。 我知道,我还可以在联合材料中使用XMLHttpRequest功能,但无法确定哪一种方法更好。

任何建议都将受到高度赞赏。

Thanks, Andy

问题回答

首先,你们需要了解你与阿加西做些什么,因为有不同的方法使阿加西人叫作 j,让人使用基本特性。

//Handle the ajax in the event click of your button with ID MyButton
$( #MyButton ).click(function(){
    $.ajax({
       type: "Type of your http Request could be GEt or Post",
       url: " the url where you obtain that xml",
       data: "ïf you need to pass some data to the url"
       dataType: "in your case should be XML which is the data type that you re going to handle in the success function",
       success: function(data){ 
            //parse your xml which it contains in the var data
            //You could set the data parse in your div with a append or html method
       } define a function or put a function already defined ,
       error:  define a function in case of error 
    });
});

。 The doc about ajax in jquery

您可以找到有关方法的文件。

。 在这里,你可以如何用jquery par食Xml。





相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签