如何将“appName”和“rating”从初始点击函数传递到“parse”函数?预先感谢您的任何帮助。我尝试过使用data: {appName: appName, rating: rating}
,但如果确实有效,我仍然不确定如何在“解析”函数中捕获数据
<script>
$(document).ready(function(){
$('.one, .two, .three, .four, .five').click(function(){
//get the app name that's to be rated.
var appName = $(this).parents('*:eq(4)').text();
appName = appName.split("\n");
appName = appName[2]
//get the rating given to the app.
var rating = $(this).attr('class');
if(rating == 'one'){
rating = 1;
}
else if(rating == 'two'){
rating = 2;
}
else if(rating == 'three'){
rating = 3;
}
else if(rating == 'four'){
rating = 4;
}
else if(rating == 'five'){
rating = 5;
}
$.ajax({
url: 'http://xxxxxx',
dataType: 'xml',
success: parse,
error: loadfail
});
});
});
</script>
<script>
function loadfail(){
alert("Error: Failed to read file!");
}
function parse(document){
$(document).find("ViewAll").find("ROW").each(function(){
var optionLabel = $(this).find('SC_DF_FIELD_1').text();
var optionValue = $(this).find('SC_DF_FIELD_4').text();
alert(optionLabel + ":" + optionValue);
});
}
</script>