2012-03-04 12 views
1

スパンクをクリックしたときにWebサービスからデータを取得するためにjQuery/Ajax $ .postを実行するクリック機能があります。クリック機能にFirebugブレークポイントが設定されていると、すべてが期待通りに機能します(新しいテーブルtrがテーブルに追加されます)。ブレークポイントが設定されていない場合、スパンをクリックすると何も起こりません。 Firebugはエラーを表示しません。私は他の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'); 
       } 
      }); 
    } 

    }); 

ご協力いただければ幸いです。

答えて

0

あなたのデータが不適切に形成されたと思われます。ブレークのコードをtry {} catch {}の中に入れて、生成されたエラーを確認してください。また、あなたのajaxリクエストにエラー処理を追加することも良い考えです。

+0

OK、私はtry {} catch {}ブロックをいくつか入れましたが、私はまだエラーをキャッチしていません。私はFirebugの$ .postから戻ってくるXMLを見てきましたが、私はそれに何の問題も見ません。そして、xml2jsonモジュールが問題なく処理しています。私はまだ混乱している。 –

+0

'$'( '#myerror')。text( 'inside'); 'を改行なしの関数の最初の行に追加すると、新しいdivにテキストが表示されますか?エラー処理をajaxリクエストに追加しましたか? – shaun5

+0

ブレークポイントがあるときに "inside"が表示されますが、ブレークポイントがないときは表示されません。私はエラー処理をajaxリクエストに追加しましたが、エラーは表示されません。 –

関連する問題