jquery.ajax() 使用来自 mysql 的 json 数据

标签 jquery mysql ajax json

我有一个创建 json 数据并对其进行编码的页面。如果我转到该页面,输出如下所示:

{"hail":
    [
        {"date":"140714","time":"1646","size":"100","city":"3 ESE HOUSTONIA","county":"PETTIS","state":"MO","lat":"38.88","lon":"-93.31","other":"(EAX)"},
        {"date":"140714","time":"1649","size":"100","city":"HUGHESVILLE","county":"PETTIS","state":"MO","lat":"38.84","lon":"-93.3","other":"US POSTAL WORKER WITH A QUARTER SIZED HAIL REPORT. (EAX)"},
        {"date":"140714","time":"1742","size":"175","city":"7 NNE COOLIDGE","county":"HAMILTON","state":"KS","lat":"38.14","lon":"-101.96","other":"(DDC)"}
    ]

然后我尝试使用

function addMarker(){
    alert("success 1");
    var infowindow =  new google.maps.InfoWindow({
            content: ''
        });

        jQuery.ajax({
            url : '/data/hail',
            dataType : 'json',
            success : function(response) {
                alert("SUCCESS");

                    hail = response.hail;

                    // loop through places and add markers
                    for (h in hail) {

                        //create gmap latlng obj
                        tmpLatLng = new google.maps.LatLng( hail[h].lat, hail[h].lon);

                        // make and place map maker.
                        var marker = new google.maps.Marker({
                            map: map,
                            position: tmpLatLng,
                            title : hail[h].city
                        });

                        // not currently used but good to keep track of markers
                        markers.push(marker);

                    }

                }
        })

    setAllMap(map);
}

第一个警报响起,但第二个警报从未被调用。我的主索引页上包含 jquery

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

最佳答案

也许是线条

var infowindow =  new google.maps.InfoWindow({
        content: ''
    });

出现错误。浏览器控制台上肯定有一些错误。

Ajax 调用是正确的。

关于jquery.ajax() 使用来自 mysql 的 json 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25489383/

相关文章:

mysql - 在 MySQL 中订购发票号码和字母

mysql - InnoDB 导出损坏

mysql - 如果 mysql 查询为空,则程序崩溃

javascript - 如何解码 JSON 对象并对其进行迭代?

javascript - 在发送更新数据之前需要提交两次表单

php - 为动态添加的内容注册事件处理程序

javascript - 如何将数据列表分配给输入?

php - 使表格在排序时显示交替的颜色背景

jquery append 功能打乱了 html 布局

jquery - Uploadify、Flash session 和 Rails 2.3.8