-1

我沒有收到第二個Ajax請求的響應。我試圖在Google地圖上顯示一個僅包含一個標籤的谷歌信息窗口,當某個標準匹配時,否則我想顯示兩個標籤。我認爲我可以輕鬆地用另一個具有定製行爲的標記函數來實現這一點,但我沒有收到任何迴應。任何幫助,這總是讚賞。提前致謝。2nd ajax請求沒有響應

// click event handler 
    google.maps.event.addListener(marker, 'click', function() { 

     var ecoli_array = []; 
     var marker = this; 
     var str = ""; 
     var beach_status; // beach_status flag 

     // load gif before ajax request completes 
     infoWindow.setContent('<img src="img/loading.gif" alt="loading data"/>'); 
     infoWindow.open(map, marker); 

     // override beach data when a beach is closed 
     beach_status = this.getBeachStatus(); 
     beach_status = beach_status.toLowerCase(); 
     if (beach_status === 'closed') { 
      str = [ 
        '<h1>' + this.beach_name + '</h1>', 
        '<h3>' + this.beach_region + '</h3>', 
        '<p>' + this.status_description + '</p>' 
       ].join(''); 
      infoWindow.setContent(str); 
      infoWindow.open(map, marker); // changed this to marker to resolve issue 


     } else { 

      // chained ajax invocations 
      if (this.displayOnlyAlgaeResults === false) { 
       // Standard Use case 
       $.when(this.getEcoliData(), this.getAlgaeData()).done(function (data1, data2) { 
        str += marker.getHeader() + marker.afterGetEcoliData(data1[0].rows); 
        str += marker.afterGetAlgaeData(data2[0].rows); 
        infoWindow.setContent(str); 
        infoWindow.open(map, marker); // changed this to marker to resolve issue 
        // render tabs UI 
        $(".tabs").tabs({ selected: 0 }); 

       }); // end when call 
      }else{ 
       // Algae Only Use Case 
       var d = this.getOnlyAlgaeData(); 
       console.log(d); 
       $.when(this.getOnlyAlgaeData()).done(function (rsp) { 
        //console.log(rsp); 
        str += marker.getAlgaeHeader() + marker.afterGetOnlyAlgaeData(rsp[0].rows); 
        //str += marker.afterGetOnlyAlgaeData(data2[0].rows); 
        infoWindow.setContent(str); 
        infoWindow.open(map, marker); // changed this to marker to resolve issue 
        // render tabs UI 
        $(".tabs").tabs({ selected: 0 }); 

       }); // end when call 

      } // end inner if else 
     } // end outer if else 

    }); // End click event handler 

getOnlyAlgaeData: function() { // begin getAlgaeData 
      var obj; 

      var queryURL = "https://www.googleapis.com/fusiontables/v1/query?sql="; 
      var queryTail = '&key=xxxxx&callback=?'; 
      var whereClause = " WHERE 'Beach_ID' = " + this.beach_id; 

      var query = "SELECT * FROM xxxx " 

      + whereClause + " ORDER BY 'Sample_Date' DESC"; 

      var queryText = encodeURI(query); 

      // ecoli request 
      return $.ajax({ 
       type: "GET", 
       url: queryURL + queryText + queryTail, 
       cache: false, 
       dataType: 'jsonp' 
      }); 

     }, // end getAlgaeData method 



     // added afterGetOnlyAlgaeData 
     afterGetOnlyAlgaeData: function (data) { 
      var algae_rows_str = ""; 
      algae_rows = data; 

      var algae_rows_str = [ 
        '<div id="tab-1">', 
       '<h1>' + this.beach_name + '</h1>', 
       '<h3>' + this.beach_region + '</h3>', 
       '<table id="algae_table " class="data">', 
       '<tr>', 

        '<th>Sample Date</th>', 
        '<th class="centerText">Blue Green Algae Cells <br/>(cells/ mL) </th>', 
        '<th>Recreational Water Quality Objective <br/>(100,000 cells/mL)</th>', 
        '<th class="centerText">Algal Toxin Microcystin <br/> (&#956g/L)</th>', 
        '<th>Recreational Water Quality Objective <br/> (20 &#956g/L)</th>', // &mu instead of u 
       '</tr>' 
      ].join(''); 

      //console.log(algae_rows); 

      if (typeof algae_rows === 'undefined') { 
       algae_rows_str = [ 
        '<div id="tab-1">', 
         '<h1>' + this.beach_name + '</h1>', 
         '<h3>' + this.beach_region + '</h3>', 
         '<p>This season, no algal blooms have been reported at this beach.</p>', 
        '</div>', 
        '</div>', 
        '</div>', 
        '</div>' 
       ].join(''); 
      } else { 

       for (var i = 0; i < algae_rows.length; i++) { 
        //console.log(rows[i]); 
        //algae_rows_str += '<tr><td>' + formatDate(algae_rows[i][2]) + '</td><td class="centerText">' + checkAlgaeToxinCount(algae_rows[i][3]) + '</td><td>' + checkAlgaeToxinForAdvisory(algae_rows[i][4]) + '</td><td class="centerText">' + checkAlgaeCount(algae_rows[i][5]) + '</td><td>' + checkBlueGreenAlgaeCellsForAdvisory(algae_rows[i][6]) + '</td></tr>'; 
        algae_rows_str += '<tr><td>' + formatDate(algae_rows[i][2]) + '</td><td class="centerText">' + checkAlgaeCount(algae_rows[i][5]) + '</td><td>' + checkBlueGreenAlgaeCellsForAdvisory(algae_rows[i][6]) + '</td><td class="centerText">' + checkAlgaeToxinCount(algae_rows[i][3]) + '</td><td>' + checkAlgaeToxinForAdvisory(algae_rows[i][4]) + '</td></tr>'; 
       } 
       algae_rows_str += '</table>' 
       algae_rows_str += '</div></div></div>'; 
       //return algae_rows_str; 

      } //end if 
      return algae_rows_str; 

     }, // end afterGetOnlyAlgaeData 



    }); // ====================end marker 

我基本上是複製將會包含相同的功能,給他們一個稍微不同的名稱和定製的每個功能,以顯示1個選項卡,而不是兩個,但我沒有得到任何迴應。

想法?

+0

「但我沒有得到迴應」是什麼? ajax請求?將其從代碼的其餘部分分離出來並進行調試。 –

+0

其內呼叫$。當呼叫 – Michael

+0

是的,我明白這一點。採取第一步,並找出爲什麼響應是空的。 (或至少確認它實際上是空的,而不僅僅是一個邏輯錯誤) –

回答

0

感謝您的幫助,它最終變得簡單。

我錯誤地引用了響應。 IE瀏覽器。我更改以下行:

str += marker.getAlgaeHeader() + marker.afterGetOnlyAlgaeData(rsp[0].rows); 

str += marker.getAlgaeHeader() + marker.afterGetOnlyAlgaeData(rsp.rows); 

天啊!