在jquery ajax请求中获取xml元素属性值

在jquery ajax请求中获取xml元素属性值,jquery,xml,Jquery,Xml,我有一个xml文件,格式如下 <Products> <Product id="1"> <ProductName>RegEB-Tote</ProductName> <ImageFileName>ToteTank_350g.png</ImageFileName> </Product> <Product id="2"> <ProductName>RegEB-Drum</Prod

我有一个xml文件,格式如下

<Products>
<Product id="1">
  <ProductName>RegEB-Tote</ProductName>
  <ImageFileName>ToteTank_350g.png</ImageFileName>
</Product>
<Product id="2">
  <ProductName>RegEB-Drum</ProductName>
  <ImageFileName>N/A</ImageFileName>
</Product>
<Product id="3">
  <ProductName>RegEB-5Gal</ProductName>
  <ImageFileName>5Gallon.png </ImageFileName>
</Product>
<Product id="4">
  <ProductName>RegEB-Gal</ProductName>
  <ImageFileName>GalSqueezeBottle.png</ImageFileName>
</Product>
prodid和fieldheight变量正在获得正确的值。变量filename不是$(xml)的if部分。find不正确,添加后台css的语法错误。正确的代码如下

 if ($(this).attr('id') === prodid) {
                       var filename = $(this).find('ImageFileName').text();
                       $('#fld_productDetailImage').css({ 'height': fieldheight, 'background': "url(../Images/ProductImages/" + filename + ") no-repeat center" });
                    }
 if ($(this).attr('id') === prodid) {
                       var filename = $(this).find('ImageFileName').text();
                       $('#fld_productDetailImage').css({ 'height': fieldheight, 'background': "url(../Images/ProductImages/" + filename + ") no-repeat center" });
                    }