数组显示未定义的jQuery发布功能 [英] array showing undefined outside the jquery post funtion

查看:58
本文介绍了数组显示未定义的jQuery发布功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友

我正在尝试使用$ .post()从数据库中获取数据,它会向我返回数据
我再次在拳头中使用$ .post()
我试图将数据推入第二个$ .post()
中的数组中 数组长度显示在第二个$ .post()内部,但在它外部显示长度0

以下是我的代码

Hello Friends

I am trying to get the data from database using $.post() it returns me data
I am again using $.post() inside the fist one
and i am trying to push that data in array inside second $.post()
array length is showing inside second $.post() but outside it it is showing length 0

Below is my code

$.post('/Common/getInfo/', null, function (data) {
    var desc = [];
    var ultlng =[];
    var count = 0;

    for (var i = 0; i < data.length; i++) {
        desc.push(data[i].Description);
        $.post('/Common/getLatlngInfo/', { id: data[i].ID }, function (data1) {

            for (var j = 0; j < data1.length; j++) {
                if (j == 0) {
                    ultlng.push(new google.maps.LatLng(data1[j].Latitude, data1[j].Longitude));
                }

                if (data1.length > 1) {
                    if (j == data1.length - 1) {
                        var flightPlanCoordinates = [
                                    new google.maps.LatLng(data1[0].Latitude, data1[0].Longitude),
                                    new google.maps.LatLng(data1[1].Latitude, data1[1].Longitude),
                                    new google.maps.LatLng(data1[2].Latitude, data1[2].Longitude),
                                    new google.maps.LatLng(data1[3].Latitude, data1[3].Longitude),
                                    new google.maps.LatLng(data1[4].Latitude, data1[4].Longitude)
                        ];
                        var flightPath = new google.maps.Polyline({
                            path: flightPlanCoordinates,
                            geodesic: true,
                            strokeColor: '#007ACC',
                            strokeOpacity: 1.0,
                            strokeWeight: 3
                        });

                        flightPath.setMap(map);
                    }
                }
                else {
                    ultlng.push(new google.maps.LatLng(data1[j].Latitude, data1[j].Longitude));
                }
            }
        });
    }

    for (var i = 0; i < desc.length; i++) {
        marker = new google.maps.Marker({
            map: map,
            position: ultlng[i]
        });

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

                if (!infowindow) {
                    infowindow = new google.maps.InfoWindow();
                }

                infowindow.setContent("<html><body><div style="min-height:50px; max-width: 200px;">" + data[i].Description + "</div></body></html>");
                infowindow.open(map, marker);
            });

        })(i, marker);
    }
});




将ultlng []数组长度设为0,应为5
当5个5个元素被推入其中时

但是在$ post()之外显示的是长度

请给我解决方案,

在此先感谢




getting ultlng[] array length as 0 it should be 5
as 5 five elements are pushed into it

but outside $post() it is showing o lenght

Please get me solution for this,

Thanks in advance

推荐答案

.post()它返回我数据
我再次在第一个拳头内使用
.post() it returns me data
I am again using


.post() 我试图将数据推入第二个数组中的数据
.post() inside the fist one
and i am trying to push that data in array inside second


.post()
数组长度显示在第二个
.post()
array length is showing inside second


这篇关于数组显示未定义的jQuery发布功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆