javascript - How to load the data without clicking on the link? -


i developing mvc app. trying develop comment box.

i have written code , in code , have written process like, when user click on show comment link comments appeared.

now, want change functionality, without clicking on show comments button , comments should load.

i trying not working.

show comments link code

 <div class="span12" style="margin-left:0px; margin-top:50px;">       <span style="font-size:16px;">           @ajax.actionlink("show comments", null, null, null, new { id = model.id, @class = "addremark" })          <div class="remarkbox"></div>         <span class="commentadd"></span>       </div> 

i want load comments when page load, expecting commments show load while loading page, still want click on show comment link.

 $(document).ready(function () {      $('a.addremark').click(addremarkclick);      // call on load     addremarkclick();      });      function addremarkclick(event)     {          var url = '@html.raw(url.action("showcommentbox", "comment", new { id = "idvalue", entitytype = "payment" }))';         if (typeof event !== 'undefined') url = url.replace("idvalue", event.target.id);         else url = url.replace("idvalue", $('a.addremark')[0].id);         $('.remarkbox').load(url);         $(this).closest('div').find('div.remarkbox').show();         return false;     }  function addremarkclick()     {         alert("clciked");         var url = '@html.raw(url.action("showcommentbox", "comment", new { id = "idvalue", entitytype = "payment" }))';          if (typeof event !== 'undefined') url = url.replace("idvalue", event.target.id);          else url = url.replace("idvalue", $('a.addremark')[0].id);          $('.remarkbox').load(url);          $(this).closest('div').find('div.remarkbox').show();          return false;     } 

the best approach load page first , using js, list of show comment links available $('a.addremark') , instead of triggering click event, can iterate on collection , make ajax calls comments loaded during runtime without user clicking on link.

also, useful have settimeout javascript call refreshes comments on page after particular duration, users not have refresh page or click on links view updated comments. can see similar approach used in stackoverflow asked me click reload post view edits. give better usability.

edit

the following can steps

  1. page load completes, after document ready, call javascript method finds links class addremark.

  2. for each link element, associate post id comment fetched for

  3. make ajax call postid , comments , update in corresponding div's.

  4. the above method can passed parameter setinterval of javascript method. method please refer here


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -