2013-03-26 3 views
0

Я просто пытаюсь загрузить некоторые простые XML-данные с помощью AJAX, но это не влияет, и я не могу на всю жизнь найти ошибку. Любая помощь приветствуется. Вот код:Простая загрузка jQuery AJAX XML не работает

Для страницы:

<html> 
<head> 
<title>Big Skinny Wallet Helper</title> 
<style> 
#nav 
{ 
position:absolute; 
left:0px; 
width:300px; 
background-color:#b0e0e6; 
} 
#content 
{ 
position:absolute; 
left: 300px; 
} 
</style> 
<script src="http://code.jquery.com/jquery-latest.js"></script 
</head> 
<body> 
<div id="nav"> 
This is text on the left. 
<form> 
<input type="radio" name="gender" class="gender" id="male" value="male">Male<br /> 
<input type="radio" name="gender" class="gender" id="female" value="female">Female<br  /> 
</form> 
</div> 

<div id="content"> 
This is the main content area. 
</div> 

<div> 
</div> 

<script> 
$(document).ready(function() { 
$.get('wallets.xml', function(data) { 
    $('#content').empty(); 
    $(data).find('wallet').each(function() { 
     var $wallet = $(this); 
     var html = '<div class="wallet">'; 
     html += '<h3 class="name">' + $wallet.attr('name'); 
     html += '</h3>'; 
     html += '</div>'; 
     $('#content').append($(html)); 
    }); 
}); 

}); 
</script> 
</body> 
</html> 

Для XML:

<?xml version="1.0" encoding="UTF-8"?> 
<wallets> 
<wallet name="Compact Sport" material="nylon" gender="male"> 
    <description> 
     This is the latest bi-fold wallet in our series of super thin and  light sport wallets featuring four card pockets. Since most people only use 4-6 cards  regularly, just use the front two pockets for those cards and stack & store all those other cards in the hidden 2 storage pockets--go minimalist by keeping your material layers to a minimum. The favorite thin wallet used every single day by the Big Skinny founder. 
    </description> 
</wallet> 
<wallet name="Curve" material="nylon" gender="male"> 
    <description> 
     Front pocket wallet-carriers, this is the model for you! We hate the state the obvious, but hey, it's fun: the curve is designed with two-rounded edges to fit neatly in your front or back pants pocket. Crafted from tough, machine-washable, nylon micro-fiber, this ultra thin wallet can hold about 20 plastic cards and cash. The pockets and billfold area are lined with a rubbery coating to help prevent your goods from sliding out: smart! 
    </description> 
</wallet> 
</wallets> 
+0

Какие ошибки вы на самом деле получаете? Пожалуйста, опишите вашу проблему. – hyde

+0

проверьте вашу консоль на наличие ошибок –

+0

Проблема связана с данными xml, она дает синтаксический анализ –

ответ

0

Ваш XML не проверка. & должно быть &amp;.

Для справок в будущем, попробуйте this validator.

+0

Спасибо! Кажется, это исправлено. – bmcswee

+0

Сладкий. Если вы создаете этот XML-файл, вы можете рассмотреть [HtmlEncoding] (http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.htmlencode.aspx) данные, чтобы это не повторилось. – davehale23

Смежные вопросы