2

I have made a cgi program in C, which generates HTML, and I would like to replace a part of a HTML page with it. So, using jquery I have tried to get the output of my cgi using $.ajax(),$.get() or $.post() but it doesn't work and I found nothing relevant in firefox and chromium's debugger. I run Apache localy, and the logs say it did have a request

127.0.0.1 - - [20/May/2013:01:19:32 +0200] "GET /cgi-bin/test_cgi HTTP/1.1" 200 682

I have looked for hours, and it seems like people are using the code just like I do but it works for them, not for me, so I'll just paste it and let you take a look to what is wrong

javascript(jquery):

$(document).ready(function() {
    $('#button_ajax').click(function() {
        alert("success1");
        $.get('http://localhost/cgi-bin/test_cgi', function(data) {
                    //$('#ajax').empty().append(data);
            alert("success2");
        });
    });
});

html:

<button id="button_ajax">Click here!</button>
<div id="ajax">
<p>Some random test</p>
</div>

There is a pop-up for "success1", but then nothing for "success2" And here is what I get in firefox debugger

> [01:19:32,898] GET http://localhost/cgi-bin/test_cgi [HTTP/1.1 200 OK
> 2ms]

with chromium debugger I get this

XMLHttpRequest cannot load http://localhost/cgi-bin/test_cgi. Origin null is not allowed by Access-Control-Allow-Origin.

Anyone up for some recommandations?

1 Answer 1

2

I'm able to run the code as you've presented it. I have also alerted the data so I can see that it is indeed retrieving the contents of the page. How does yours differ?

This might indicate that there is some issue with the configuration of your web server.

<html>
   <head>
      <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
      <script type="text/javascript">
     $(document).ready(function() {
        $('#button_ajax').click(function() {
           alert("success1");
           $.get('http://localhost:8888/so/test2.html', function(data) {
               //$('#ajax').empty().append(data);
               alert("success2" + data);
           });
        });
    });
      </script>
   </head>
   <body>
      <button id="button_ajax">Click here!</button>
      <div id="ajax">
         <p>Some random test</p>
      </div>
   </body>
</html>
6
  • This is the whole code pastebin.com/8Zvb8eSs And I'm not sure, what could I have done wrong to get Apache to be messy? It doesn't say anything wrong about my last try (which didn't work) In access_log file: 127.0.0.1 - - [20/May/2013:03:26:46 +0200] "GET /cgi-bin/test_cgi HTTP/1.1" 200 682 In error_log file: [Sat Mar 24 21:03:05 2012] [warn] RSA server certificate CommonName (CN) `localhost' does NOT match server name!? (which was way earlier) and in cgi_errors_logs nothing about this one cgi This is weird don't you think?
    – toor
    May 20, 2013 at 1:33
  • Are you able to navigate to the cgi url directly?
    – cloudworks
    May 20, 2013 at 1:55
  • Yes, localhost/cgi-bin/test_cgi launchs the html code into the browser
    – toor
    May 20, 2013 at 2:00
  • Interesting; have you tried using a relative path to access the CGI file? Your web server may be interpreting it as a cross origin resource.
    – cloudworks
    May 20, 2013 at 3:26
  • 2
    omg it was because my html file was not in the apache directories… I didn't know it HAD TO be, thank you so much I wouldn't have found this on my own, I love you
    – toor
    May 20, 2013 at 3:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.