$.ajax({
error: function(){alert('Error retrieving candidates from database.');},
success: function(data){
var template = ' <div class="candidate" id="candidate-$1">\r\n\
<div class="header">\r\n\
<div class="picture"><a href="$2" class="target[\'_blank\']"><img src="pictures/$1.jpg" alt="$4" /></a></div>\r\n\
<h2><a href="$2" class="target[\'_blank\']">$4</a></h2>\r\n\
<h3>$5</h3>\r\n\
<div class="stats">\r\n\
<span class="alike" title="You have $6% in common with John Galt."><span class="number">$6</span>%</span>\r\n\
<span class="similarity-graph" title="$7% of survey takers have less in common with $3 than you do; $8% of survey takers have more in common with $3 than you do.">$7,$8</span>\r\n\
<span class="certainty-graph" title="PrezMatch.com is $9% certain that John Galt is your best match.">$9</span>\r\n\
</div>\r\n\
</div>\r\n\
<div class="tabs">\r\n\
<span class="active profile-tab"><a href="javascript:;">Profile</a></span>\r\n\
<span class="keypoints-tab"><a href="javascript:;">Key points</a></span>\r\n\
</div>\r\n\
<div class="active content profile-content">\r\n\
$10\r\n\
</div>\r\n\
<div class="content keypoints-content"></div>\r\n\
</div>\r\n';
var result = '\r\n';
$(data).children().first().children().each(function(){
var temp = template;
temp = temp.replace(/\$1/g, $(this).attr('id'));
temp = temp.replace(/\$2/g, $(this).children('link').first().html());
temp = temp.replace(/\$3/g, $(this).attr('gender').toLowerCase() == 'm' ? 'him' : 'her');
temp = temp.replace(/\$4/g, $(this).children('name').first().html());
temp = temp.replace(/\$5/g, $(this).children('subtitle').first().html());
temp = temp.replace(/\$6/g, '<span class="percent-in-common"></span>');
temp = temp.replace(/\$7/g, '<span class="less-in-common"></span>');
temp = temp.replace(/\$8/g, '<span class="more-in-common"></span>');
temp = temp.repalce(/\$9/g, '<span class="percent-certain"></span>');
temp = temp.replace(/\$10/g, $(this).children('profile').first().html());
result += temp;
});
result = $(result);
$('#candidates').prepend(result);
},
url: 'data/candidates.xml'
});
我無法爲我的生活診斷出這個問題。我有一個非常相似的方法來從questions.xml中得到問題,這很好,但是這個在jquery.min.js文件中產生了一個錯誤。(jQuery)Uncaught TypeError:無法調用未定義的方法'替換'
請幫忙嗎?