Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Loading results (via ajax) from a CGI

1 view
Skip to first unread message

bu...@alejandro.ceballos.info

unread,
Nov 27, 2009, 8:58:37 AM11/27/09
to beginn...@perl.org
I have a CGI (made with cgi.pm) that receive a parameters, check
against a DB and returns a text with "not found" or "OK found"
message. Pretty simple.

In other site, i have an ajax routine that sends the parameters (via
get) and is expected to capture the resulting page, but is not
working. If I try with a static page, there is not problem, only when
calling that CGI.

I try changing the content-type (html, text) and specifing the status
header (200 ok) but my ajax routine receive an 0 status code. I tested
the CGI directly via browser and it works fine

Any idea where is going this?


If this help, here is my ajax routine:

function ShowInstallInfo (int_value)
{
var ajax_this;
if (window.XMLHttpRequest) { ajax_this = new XMLHttpRequest(); }
else { ajax_this = new ActiveXObject("Microsoft.XMLHTTP"); }
ajax_this.onreadystatechange = function ()
{ if (ajax_this.readyState==4 || ajax_this.readyState=="complete")
{ alert("Results: "+ajax_this.status+" text:"+ajax_this.responseText); }
};
// This URI works (test): 'http://www.hunlock.com/examples/notajax.html';
// This URI DOES NOT works (mine):
'http://keys.siteupsoftware.com/cgi-bin/install_verify.cgi?value='+int_value;
var myurl = 'http://www.hunlock.com/examples/notajax.html';
ajax_this.open("GET", myurl, true);
ajax_this.send(null);
}


Alexander Krasnorutsky

unread,
Nov 27, 2009, 10:39:05 AM11/27/09
to beginn...@perl.org

Is the `onreadystatechange' handler called when readyState == 3?

--
Alexander Krasnorutsky.

Dermot Paikkos

unread,
Nov 27, 2009, 9:20:42 AM11/27/09
to beginn...@perl.org
This is of course a javascript/ajax question to a perl list....

> -----Original Message-----
> From: bu...@alejandro.ceballos.info
> [mailto:bu...@alejandro.ceballos.info]
> Sent: 27 November 2009 13:59
> To: beginn...@perl.org
> Subject: Loading results (via ajax) from a CGI
>
> Any idea where is going this?
>
>
> If this help, here is my ajax routine:
>
> function ShowInstallInfo (int_value)
> {
> var ajax_this;
> if (window.XMLHttpRequest) { ajax_this = new XMLHttpRequest(); }
> else { ajax_this = new ActiveXObject("Microsoft.XMLHTTP"); }
> ajax_this.onreadystatechange = function ()


Take out the if clause and see what you get.

> { if (ajax_this.readyState==4 ||
ajax_this.readyState=="complete")
> { alert("Results: "+ajax_this.status+"
> text:"+ajax_this.responseText); }
> };

// { if (ajax_this.readyState==4 || ajax_this.readyState=="complete")


{ alert("Results: "+ajax_this.status+"
text:"+ajax_this.responseText); }

// };

Good luck,
Dp.


Rene Schickbauer

unread,
Dec 1, 2009, 7:01:21 AM12/1/09
to beginn...@perl.org
bu...@alejandro.ceballos.info wrote:
> I have a CGI (made with cgi.pm) that receive a parameters, check against
> a DB and returns a text with "not found" or "OK found" message. Pretty
> simple.
>
> In other site, i have an ajax routine that sends the parameters (via
> get) and is expected to capture the resulting page, but is not working.
> If I try with a static page, there is not problem, only when calling
> that CGI.

The may be a problem with your headers. What i mean is, is the browser
(wrongly) caching the page you request?

Try setting the correct headers. Also, you might add an ever-changing
dummy value to your request to trick the browser into thinking this is a
new, non-cached page.

You have
var myurl = 'http://server/script.cgi?value='+int_value;

change to:

var myurl = 'http://server/script.cgi?value='+int_value + '&dummyvalue='
+ now.getTime();

LG
Rene

0 new messages