简体   繁体   English

如何从Java提取数组到Ajax

[英]how to extract array from java to ajax

I get the values from database to time array as follow 我从数据库到时间数组获取值,如下所示

int[] time=Manager.playTime() ;               
responsedata.put("status", "success");
responsedata.put("play", time);

And i am sending this time array to ajax in javascript file as follow 我将这个时间数组发送到javascript文件中的ajax,如下

 success:function(response){
     $('body').css('cursor', 'default');
     if(response.status == 'success'){
        for( var i=0;i<response.play.length;i++){
           alert("playtime---"+response.play[i]);
     }

but here i am not getting the values from array .Please help me 但是在这里我没有从array中获取值。请帮助我

Thanks 谢谢

You responsedata seems to be a Java Map. 您的responsedata似乎是Java Map。

Try to use this in your success function 尝试在成功功能中使用它

success:function(response){
     $('body').css('cursor', 'default');
     if(response.status == 'success'){
        $.each(response.play, function (value) {
             alert("playtime---"+value);
        });
     }
}

In your ajax you are getting whole object in response ie response. 在您的ajax中,您将获得整个对象作为响应,即响应。 You can get your play object by response ie response.play . 您可以通过响应(即response.play获取播放对象。 now iterate the the values from play object. 现在迭代播放对象的值。

for (var i = 0; i < response.play.length; i++) {
   //iterate your values here
    alert(response.play[i].object_key);
   //object_key is temparary name of your play object so give a proper key here.
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM