user3897102
user3897102

Reputation: 23

calling cgi script from div and javascript/jquery

I have a index.cgi which has a div like

<div id="AddCodeTab">
    <div id="CodeContainer" style="width: 100%;"></div>
</div>

So this div gets its content from addcode.js

I have another cgi page databasecall.cgi

So how do I define the addcode.js so that dropdown box in the div will get its value from another cgi page databasecall.cgi

Upvotes: 2

Views: 1140

Answers (1)

Host Lawn
Host Lawn

Reputation: 139

In your addcode.js include the following code.

$(document).ready(function(){

    $.ajax({url: "databasecall.cgi", success: function(result){
        $("#ajaxElement").html(result);    
    }});

});

And your index.cgi should have jQuery Library loaded. It should look something similar to this...

<!doctype html>
<html>
<head>
</head>
<body>
<h1>Loading a CGI file via jQuery/AJAX</h1>
<!-- more content -->
<header id="pageHeader"><h2>This section is populated using jQuery/AJAX</h2>
<div id="ajaxElement"></div>
</header>
<!--more content -->    
<!-- absolute or relative path to your jQuery Library.  You can also use CDN from jQuery.org.  I use npm to install mine.   -->
<script src="/node_modules/jquery/dist/jquery.min.js"></script>
<!-- make sure your path to jQuery libray is correct -->
<script src="addcode.js"></script>
</body>
</html>

Upvotes: 2

Related Questions