PDA

View Full Version : Javascript/AJAX app breaks when uploaded?


rollercoaster375
2007-11-03, 22:20
I've—more for an academic exercise than anything else—made something of an implementation of Terminal in Javascript/XHTML. On my local machine, it's capable of sending "commands" ala ajax to a PHP handler file, which works moderately well. However, when I upload it to a 'real' server the ajax functionality dies entirely. Anybody have a clue as to why this would be the case?

http://sparkbomb.com/Coaster/term/ <-- The uploaded version. It [i]should perform an ajax request when you hit enter (Rather than doing absolutely nothing).

Oh, I should note that I don't think it works at all in Safari, and it looks best in Firefox (Camino has cursor and scrollbar glitches due to the way I have the thing implemented [A textarea has focus behind the displayed div]...). I'll clean it up in other browsers as soon as I can get it working in one of them ;)

Brad
2007-11-03, 22:45
This could have something to do with it:

http://i8.tinypic.com/2njwmfc.png

When you press enter, your code is getting back this from its request to handler.php:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>403 Forbidden</TITLE>
</HEAD><BODY>
<H1>Forbidden</H1>
You don't have permission to access /Coaster/term/handler.php
on this server.<P>
<P>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.
<HR>
<ADDRESS>Apache/1.3.37 Server at sparkbomb.com Port 80</ADDRESS>
</BODY></HTML>

rollercoaster375
2007-11-04, 13:39
What debugger is that? JS Console wasn't giving me anything >_>

Just chmodded it to 777... Did nothing.

Brad
2007-11-04, 13:47
The screenshot came from Safari's activity window.

The quoted HTML came from digging in Firefox with the Firebug extension.

I'll try a few other things here...

chucker
2007-11-04, 13:51
Of note, the 403 only occurs when the script is called through AJAX. When accessing it directly with no referrer, it appears to work. Sounds like some broken mod_rewrite rule?

rollercoaster375
2007-11-12, 14:54
Turns out my host filters requests based on the pattern:

!(^application/x-www-form-urlencoded$|^multipart/form-data;)

Changed the AJAX to GET instead of POST, and it works =D

http://sparkbomb.com/Coaster/term/

Brad
2007-11-12, 16:42
Can you not override that rule?

GET probably shouldn't be used for any complicated AXAJ because it has a relatively small maximum character limit, effectively the limit of the URL size your browser supports. I'm not sure what this value is in Safari or Firefox, but I know IE is capped at 2 KB. You may also run into problems with the web server's maximum length.

edit: Here's a list of rough maximums (http://www.boutell.com/newfaq/misc/urllength.html).

chucker
2007-11-12, 17:25
GET probably shouldn't be used for any complicated AXAJ because it has a relatively small maximum character limit,

Not to mention the security implications. Yeouch!

rollercoaster375
2007-11-12, 22:59
Yeah, I realize that it's not a great solution. Beyond the sheer ugliness, it's also semantically incorrect.

I can probably tamper with some headers to get around the blocker.