第二个ajax请求没有回复

时间:2017-05-04 15:00:48

标签: javascript jquery google-maps google-maps-api-3 google-fusion-tables

我没有收到第二个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个标签而不是两个,但我没有得到回复。

思想?

1 个答案:

答案 0 :(得分:0)

感谢您的帮助,最终变得简单。

我错误地引用了回复。 IE浏览器。我更改了以下行:

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

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

吉兹!