0

I have a GET method that is instantiating by clicking on the link in jsp page as

HTML:

<div class="panel accordion clearfix" id="dispdir">
    <script type="text/javascript">
        window.onload = function() {
            //showDirectorySegment(${S3DirectoryList},"folder",null);
            showBucketList(${S3BucketList});
        };
    </script>
</div>

Javascript:

function showBucketList( bucketList ) {

    markup = "<div class=\"clearfix\">";
    $("#dispdir").append(markup);
    for ( var i = 0; i < bucketList.length; i++ ) {
         var bid = "bucket_"+bucketId;
         var key = bucketList[i].replace(/ /g,"+");
         var uri = "/accountingReports?bucketName=" + key;
         var res = encodeURI(uri);
         markup = "<div class=\"well clearfix\" style=\"background-color:#A5FFED;font-size:15px\">";
         markup += "<a href='" + res + "' style=\"text-decoration:none\" id='" + pid + "'>"&nbsp;&nbsp;" + bucketList[i] + "</a></div>";
         $("#dispdir").append(markup);   
         $("#" + bid).on("click",fetchDirectory());
         bucketId++;
    }
    $("#dispdir").append("<div>");
}

Now, when ever the link is clicked it will call the server and server will return the object ${S3DirectoryList}. How to check now whether the object is returned or not.

What will be the syntax for that ?

Aki008
  • 405
  • 2
  • 6
  • 19

1 Answers1

0

You need to write this script in JSP file:

<script type="text/javascript">
        window.onload = function() {
            var object = '${S3BucketList}'; //This variable will contain value returned by server    
            //check this object for null
            //showDirectorySegment(${S3DirectoryList},"folder",null);
            showBucketList(${S3BucketList});
        };
</script>
Nikhil Talreja
  • 2,754
  • 1
  • 14
  • 20
  • I understand that but what is the best practice for implementing it, since when I click on the link, client will contact the server and then server after some time might return the result. I couldn't find the correct approach. – Aki008 Jun 27 '14 at 09:27
  • I am assuming the html you have posted is the page where the user will land after clicking the link. Do you want to check if there was data before the user lands here? – Nikhil Talreja Jun 27 '14 at 09:31
  • The get request is going from same page to server and it is returning back to same page, so yes I want to check whether data is inside ${S3DirectoryList} or not, otherwise it is getting replaced with a blank and js is returning error – Aki008 Jun 27 '14 at 09:36
  • So you want to check this before you go to server and come back? – Nikhil Talreja Jun 27 '14 at 09:44
  • No, I have some links on the web-page on which If I click server will be contacted then which returns the object on the same page rather going to another page, now How to use that object after it is returned from the server. – Aki008 Jun 27 '14 at 09:55
  • Check my edited answer. It will read your server returned variable. You can do your checks as required on it. – Nikhil Talreja Jun 27 '14 at 10:08