tags:

views:

524

answers:

3

If I call this function directly it works fine, yet if I call it from Javascript using an ajax call it wont work correctly.

I found out the reason for this, it was cause I was using $(document).ready(function ..) where I should call the functions directly after the ajax returns the results.

+2  A: 

So confusing, your perl code just outputs html without any headers (like content-type). Your javascript doesn't seem to use jQuery, and none of the referred IDs appear anywhere in your example.

Were you looking to use load something like: $('#view_span').load('filename_ajax.cgi');?
Or perhaps:

$('#view_span').load(
  'filename_ajax.cgi',
  {'target': escape(encodeURI('get_section'))},
  alertViewResult);
dlamblin
+2  A: 

At minimum, your Perl script needs to output the following kind of text before any other output:

Content-Type: text/html

Note that there must be an empty line after the Content-Type line.

If you fail to do this, the server will not send the text to the JavaScript. Typically it would trip the line

alert('There was a problem with the request.');

in your JavaScript. If you examine the value of the variable .status, it should be equal to 500, an error code which indicates your script failed.

Kinopiko
+2  A: 

Although it's a bit under-documented (at least for someone who isn't already intimately familiar with jQuery itself), have you taken a look at JQuery on CPAN?

Dave Sherohman