2012-03-14 5 views
2

私のwebservice呼び出しを正しく動作させるのに問題があります。Ajaxの結果をクリアする

私の成功の呼び出しは、LIタグのリストをULに追加します。目標は、別の呼び出しが行われる前にこれらの結果をクリアすることです。今すぐコールボタンをクリックすると、新しい結果がリストに追加されます。

私はそれを.listview( 'refresh');これをするはずだったが、それは私のためではない。

何が起こっているかに関するアイデアはありますか?

HTML

<div data-role="content" id=""> 

      <ul data-role="listview" id="Gallery" class="gallery"> 
      </ul> 

    </div> 

JS

getAlbumImages = function (album) { 
     $.ajax({ 
      url: wcfServiceUrl + "GetMediaSource?AlbumId=" + album, 
      data: '{}', 
      type: 'GET', 
      contentType: "application/x-www-form-urlencoded", 
      async: true, 
      //crossBrowser: true, 
      dataType: 'jsonp', 
      //jsonpCallback: 'MediaSource', 
      timeout: 5000, 
      success: function (data, status) { 
       $.each(data, populateImageGrid); 
      }, 
      complete: function() { 
       $("ul#Gallery").listview("refresh"); 
      }, 
      error: function() { 
       alert('There was an error loading the data.'); 
      } 
     }); 
    } 
function populateImageGrid() { 
     var photoSource, thumbSource, title, description; 
     photoSource = this.ImageSource; 
     thumbSource = this.ThumbSource; 
     title = this.Title; 
     description = this.Description; 
     imageTile += "<li><a href='" + photoSource + "'><img src='" + thumbSource + "' alt='" + title + "' /></a></li>"; 
     console.log(imageTile); 
     $("ul#Gallery").html(imageTile); 
     //$("ul#Gallery").listview(); 
     // $("ul#Gallery").listview('refresh'); 
    } 

おかげ

答えて

1

imageTileがリセットされていることを確認します。私はそのグローバル変数を想定しています。もしそうなら、それを追加するだけです。

これに変更:

success: function (data, status) { 
    imageTite = ""; 
    $.each(data, populateImageGrid); 
}, 

はそれを行う必要があります。または、グローバル変数にする理由がない場合は、それをローカル変数にしてください。

var imageTile = "<li><a href='" + photoSource + "'><img src='" + thumbSource + "' alt='" + title + "' /></a></li>"; 
+0

ありがとう。私はimageTile = ""を使ってアプローチをとった。ページ変更時に私は何をする必要があるか考えていたと思う。 –

関連する問題