jquery - getting data from cgi into javascript (ajax) -
i have made cgi program in c, generates html, , replace part of html page it. so, using jquery have tried output of cgi using $.ajax(),$.get() or $.post() doesn't work , found nothing relevant in firefox , chromium's debugger. run apache localy, , logs did have 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 hours, , seems people using code works them, not me, i'll paste , let take 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 pop-up "success1", nothing "success2" , here in firefox debugger
> [01:19:32,898] http://localhost/cgi-bin/test_cgi [http/1.1 200 ok > 2ms]
with chromium debugger this
xmlhttprequest cannot load http://localhost/cgi-bin/test_cgi. origin null not allowed access-control-allow-origin.
anyone recommandations?
i'm able run code you've presented it. have alerted data can see indeed retrieving contents of page. how yours differ?
this might indicate there issue configuration of 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>
Comments
Post a Comment