Stupid me cannot make Ajax.Request work

5 views
Skip to first unread message

FourBrane

unread,
Nov 10, 2009, 1:15:31 AM11/10/09
to Prototype & script.aculo.us
I am bumfuzzled by what "should" be a simple thing. I'm using
prototype 1.6.1. The server side is working. The chkCardNum function
gets called...but nothing fires.

<script type="text/javascript">
<!--
function chkCardNum() {
var notice = $('notice');
notice.update('Checking card number');
new Ajax.Request('https://www.somesite/cgi-bin/ajax.cgi',
{
method: 'post',
onSuccess: function(transport) {
if (transport.responseText.match(/OK/)) {
notice.update('Card number passes').setStyle({ background:
'#dfd' });
}
else if (transport.responseText.match(/N0/)) {
notice.update('The card number provided seems to have an
error.').setStyle({ background: '#fdd' });
}
},
onFailure: function(transport) {
alert('Something went wrong');
}
});
}
//-->
</script>

</head>
<body>
<div>
<form name="testform" method="post" action="#">
<p>Number: <input align="bottom" id="cardnum" name="cardnum"
type="text" size="20" value="" class="monospc" onchange="chkCardNum
()"></p>
<p id='notice'></p>
</form>
</div>
</body>
</html>

On the server end, this is all I'm using for this test.
#!/usr/bin/perl

print "Content-type: text/html\n\n";
print 'OK';

Why won't it work?

Alex McAuley

unread,
Nov 10, 2009, 6:49:35 AM11/10/09
to prototype-s...@googlegroups.com
Ajax.Request will not follow XDR

You have to make the request on the same domain and port else you will have
to use a wrapper on the server side to go off domain....



Alex Mcauley
http://www.thevacancymarket.com

FourBrane

unread,
Nov 10, 2009, 3:40:31 PM11/10/09
to Prototype & script.aculo.us
> Ajax.Request will not follow XDR
> You have to make the request on the same domain and port

Thanks.

For anyone else searching for answers to this kind of issue, "same
port" means I can't load my test page via http and then make an
Ajax.Request via https (or vice versa). On thinking about it, of
course, this makes perfect sense from a security standpoint

Pity I was hung up on "it's the same domain" and so didn't even think
about it being a cross browser issue. I could have saved myself hours
of hair tearing.
Reply all
Reply to author
Forward
0 new messages