jQuery/Ajax $ .post를 클릭하여 스팬을 클릭하면 웹 서비스에서 데이터를 가져 오는 클릭 기능이 있습니다. 클릭 기능에 Firebug 브레이크 포인트가 설정되면 모든 것이 예상대로 작동합니다 (일부 새 테이블 tr이 테이블에 추가됨). 중단 점 세트가 없으면 스팬을 클릭해도 아무런 변화가 없습니다. 파이어 버그는 오류를 표시하지 않습니다. 나는 이것이 타이밍 문제라고 다른 stackoverflow 질문에서 가정하지만, 그것에 대해 어떻게 해야할지 모르겠다. $ .ajax에서 $ .ajax로 변경하고 async를 false로 설정하려고 시도했지만 해결되지 않았습니다. 클릭 핸들러 코드는 다음과 같습니다.Ajax/jQuery 타이밍 문제
$('.rating_config').click(function(event){
event.preventDefault();
event.stopPropagation();
var that = $(this);
// calculate the name of the module based on the classes of the parent <tr>
var mytrclasses = $(this).parents('tr').attr('class');
var modulestart = mytrclasses.indexOf('module-');
var start = mytrclasses.indexOf('-', modulestart) + 1;
var stop = mytrclasses.indexOf(' ', start);
var mymodule = mytrclasses.substring(start, stop);
mymodule = mymodule.replace(/ /g, '+');
mymodule = mymodule.replace(/_/g, '+');
mymodule = encodeURI(mymodule);
// calculate the name of the property based on the classes of the parent <tr>
var propertystart = mytrclasses.indexOf('property-');
var propstart = mytrclasses.indexOf('-', propertystart) + 1;
var propstop = mytrclasses.indexOf(' ', propstart);
var myproperty = mytrclasses.substring(propstart, propstop);
myproperty = myproperty.replace(/ /g, '+');
myproperty = myproperty.replace(/_/g, '+');
myproperty = encodeURI(myproperty);
var parentspanid = $(this).attr('id');
// Remove the comparison rows if they are already present, otherwise generate them
if ($('.comparison_' + parentspanid).length != 0) {
$('.comparison_' + parentspanid).remove();
} else {
$.post('http://localhost/LearnPHP/webservice.php?user=user-0&q=comparison&level=property&module=' + mymodule + '&version_id=1.0&property=' + myproperty + '&format=xml', function(data) {
var data = $.xml2json(data);
for (var propnum in data.configuration.modules.module.properties.property) {
var prop = data.configuration.modules.module.properties.property[propnum];
console.log(JSON.stringify(prop));
prop.mod_or_config = 'config';
var item_id = mymodule + '?' + prop.property_name + '?' + prop.version_id + '?' + prop.value;
item_id = convertId(item_id);
prop.id = item_id;
//alert('prop.conformity = ' + prop.conformity);
// genRow(row, module, comparison, comparison_parentspanid)
var rowstring = genRow(prop, mymodule, true, parentspanid);
console.log('back from genRow. rowstring = ' + rowstring);
$(that).closest('tr').after(rowstring);
//$('tr#node-' + data[row].id + ' span#rating' + row.id).css('background', '-moz-linear-gradient(left, #ff0000 0%, #ff0000 ' + data[row].conformity + '%, #00ff00 ' + 100 - data[row].conformity + '%, #00ff00 100%');
var conformity_color = getConformityColor(prop.conformity);
$('tr#comparison_module_' + mymodule + '_setting_' + prop.id + ' span#module_' + mymodule + '_rating' + prop.id).css({'background':'-moz-linear-gradient(left, ' + conformity_color + ' 0%, ' + conformity_color + ' ' + prop.conformity + '%, #fffff0 ' + prop.conformity + '%, #fffff0 100%)'});
//$('tr#comparison-' + data[row].id + ' span#rating' + data[row].id).css('background','-webkit-linear-gradient(left, #00ff00 0%, #00ff00 ' + data[row].conformity + '%, #ff0000 ' + (100 - (data[row].conformity + 2)) + '%, #ff0000 100%)');
}
});
// Hide the Fix by mod column
hideFixedByModCol();
$('tr.comparison_' + parentspanid).each(function(i){
if (i % 2 == 0) {
$(that).addClass('comparison_even');
} else {
$(that).addClass('comparison_odd');
}
});
}
});
어떤 도움을 주시면 감사하겠습니다!
좋아요, try {} catch {} 블록을 여러 개 넣었지만 아직 오류가 없습니다. 파이어 버그의 $ .post에서 돌아 오는 XML을 살펴 봤는데 문제가없는 것 같다. 그리고 그것은 문제없이 xml2json 모듈에 의해 처리됩니다. 나는 아직도 혼란 스럽다. –
'$'('#'myerror '). text ('inside ');'를 추가하지 않으면 함수의 첫 번째 줄에 중단없이 텍스트가 새 div에 나타 납니 까? 오류 처리를 ajax 요청에 추가 했습니까? – shaun5
중단 점이있을 때 "inside"가 표시되지만 중단 점이 없을 때는 표시되지 않습니다. 오류 처리 ajax 요청을 추가했지만 오류를 표시하지 않습니다. –