http://www.perlmonks.org?node_id=11126745

monx663 has asked for the wisdom of the Perl Monks concerning the following question:

This is not exactly a Perl question but, I'm using Perl as the backend programming language that creates HTML so...

I am incorporating AJAX on a CMS written in Perl which has been stable for years. One of the backoffice pages of this CMS, shows a list of items that expose actions that can be carried out on this item. One of these actions is Activate/Inactivate. This is just an icon wrapped around that would call the right Perl script on the server and switch the items' status. I am trying to do this with AJAX/JSON jQuery inline, rather than enforcing a full page reload with the traditional href link to a CGI script.

I have written a script on the server that responds to AJAX called with jQuery and completes the desired action and returns dynamic results that update the corresponding hardcoded (div2log) DIV element of the page that called it. <DIV id="div2log"></DIV>

What I would like to do is include the JSON/jQuery stuff in a .js (Javascript) file on the server and only include references to this file where jQuery/AJAX is needed for any item.

I have created a js file that contains:

<script>
$(document).ready(function(){
   $("button").click(function(){
      $.ajax({url: "/cgi-bin/ajax.pl", success: function(result){
         $("#div2log").html(result);
      }});
  });
});
</script>

But I am not sure how to reference it, and pass it the params that I would have passed to a script using /cgi/script.pl?paramA=1&paramB=2&param3=3 and I am not sure how to pass it the HTML ID of the DIV that it must update with the visual result of its action on the server.

Does my question make sense?

Cheers,
Kostas