jquery - ajax is not working in perl cgi script -
hi trying execute ajax with cgi script , not sure work or not.i trying content file.
here code:
#!/usr/bin/perl use warnings; use strict; use cgi; use cgi::carp qw(fatalstobrowser); $cgi = cgi->new; print $cgi->header( -type=> "text/html" ); print <<eof; <!doctype html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"> $(document).ready(function(){ $("button").click(function(){ $.ajax({url:"test1.txt", datatype:"text", success: function(result){ $("#div1").html(result); }}).fail(function( jqxhr, textstatus, errorthrown ) { console.log(textstatus,errorthrown)}); }); }); </script> </head> <body> <div id="div1"><h2>let jquery ajax change text</h2></div> <button>get external content</button> </body> </html> eof
the same code html working when try cgi not working. don't know correct way write or not?
please suggest me correct way make working.
thanks in advance.
based on research, have print eof
:
print eof;
so whole script like:
#!/usr/bin/perl use warnings; use strict; use cgi; use cgi::carp qw(fatalstobrowser); $cgi = cgi->new; print $cgi->header( -type=> "text/html" ); print <<eof; <!doctype html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"> $(document).ready(function(){ $("button").click(function(){ $.ajax({url:"test1.txt", datatype:"text", success: function(result){ $("#div1").html(result); }}).fail(function( jqxhr, textstatus, errorthrown ) { console.log(textstatus,errorthrown)}); }); }); </script> </head> <body> <div id="div1"><h2>let jquery ajax change text</h2></div> <button>get external content</button> </body> </html> eof print eof;
example seen here: http://www.cgi101.com/book/ch6/text.html
Comments
Post a Comment