Forum Moderators: open

Message Too Old, No Replies

AJAX offline?

Not possible?

         

Hester

11:31 am on Mar 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have tested a simple AJAX script to open a small text file using GET and output it, but it only works if called from the server. Since JavaScript also works offline, I was thinking it would be able to work offline too, and grab the text file from the server without any problem. But no. Is this right - can AJAX only be used online?

I did test in different browsers and found IE6 does work offline. Since that is using a different protocol (ActiveX) that must be why. But I need it to work in Firefox and Opera too.

It just seems AJAX is limited if it does not work offline across all main browsers.

Bernard Marx

12:25 pm on Mar 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not much of a limitation really. Consider the security implications too.

Why do you want this to work offline?

trillianjedi

12:58 pm on Mar 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why do you want this to work offline?

On an intranet perhaps?

Bernard Marx

1:02 pm on Mar 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would call that "online".

The general restriction is that client-side XMLHTTP object won't make cross-domain requests. This restriction seems to be dropped by IE when the calling page is opened in the local zone. I'm not an XP user, but I think this restriction may be on there too.

Hester

1:16 pm on Mar 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, it's a demo that I've made. It works fine locally, but I need a way to access a file stored on a server. Then the file can be updated from anywhere, while the program stays on the client computer. I'm surprised if no-one has considered this scenario before...

Bernard Marx

1:47 pm on Mar 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you need to receive any information back from the server?

Rambo Tribble

3:02 pm on Mar 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is a simple matter to install Apache locally and address it as localhost. You can then run any server script (assuming you install the appropriate language module on Apache) just like it was on the web.

Assuming you are running a variety of Debian Linux on your desktop, like a responsible developer, Synaptic will allow you to automatically configure and install Apache and the appropriate modules for the server languages you wish to support. Red Hat or SuSE both have package managers that allow easy install, as well.

If you are some kind of sociopath that still runs Windows, you can get EasyPHP, which will quite easily install both Apache and the appropriate modules for PHP support. I image you can manually, at great expense in time, resources, and human capital, also install Ruby on Windows-Apache; on Linux it is a single mouse click.

I believe that at least some versions of Windows XP come with some flavor of MS server already on board. With a little investigation, some arcane rituals, and blood sacrifice, you can probably get that up and running, too.

Bernard Marx

3:23 pm on Mar 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Then the file can be updated from anywhere

Just as long as "everywhere" has a server onboard.

'Tis indeed reasonably easy to get a server up & running locally, Mr T., but this might not be feasible on every occasion.

I was going to suggest old-fashioned things like dummy image requests with data appended to query strings - that's if no info is expected in reply.

Rambo Tribble

4:42 pm on Mar 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just trying to offer the simplest possible solution. As me dear ol' Mum used to say, "From the simplest mind comes the simplest solution." I think she meant it as a compliment.

Actually, I'm a bit pressed to envision the circumstances obviating the installation of a local server, but I bow to your estimable command of the milieu.

Hester

10:09 am on Mar 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are some kind of sociopath that still runs Windows

You mean like the vast majority of people? Anyway I'm stuck with it at work and choose to use it at home, due to the immeasurable number of programs designed for it. I have Linux waiting to be installed, but don't feel the need right now, due to so many wonderful, and often free, Windows programs out there.

Anyway, I have already installed Apache and PHP onto Windows XP. But I wasn't testing the file from there, but another folder. I assumed JavaScript would be able to connect directly to a server on the internet from any folder on my PC using AJAX. Obviously not.

Now the demo only needs to download a text file. (Actually uploading might be useful too, but not right now.) What I meant by global access is that the PHP side of it would run naturally as a standard website does - so you could dial into the web page from home, work, on the move, whatever. The JavaScript is merely to reference the data locally (as it uses a nifty search-as-you-type function) while the PHP is for the maintenance of the database I need.

If only JavaScript could load and save files none of this messing around would be necessary.

Also, the demo must work for anyone who chooses to download it. So installing a local server is not a good option to require.

Rambo Tribble

2:08 pm on Mar 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As its name suggests, the XMLHttpRequest will only function with an HTTP response. You really either have to have a server or fake the use of XMLHttpRequest. Really, this isn't unreasonable, as the raisin d' eater for the XHR object is communication with a server. Nothing else.

Just so you know, there are literally thousands of open source software packages available for Linux, including the best programming editor I've used, Quanta Plus. The only valid reason to stick with Windows is if you already have hardware, the manufacturers of which haven't produced Linux drivers. Included are some mobo chipsets and some obscure peripherals, but supporting those manufacturers, whether you love Bill or not, is limiting choice and raising prices.

Rambo Tribble

2:38 pm on Mar 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oh, and if you weren't aware, Linux can run many Windows apps. I run dvdShrink and IE regularly (imagine, the world's only secure IE), but you can also run such staples as MS Office and Adobe Photoshop.

As for majorities, they're what elect our politicians, aren't they? (Can you say, "George Bush"?)

Oh, wait, I think I see your point. "Sociopath" isn't quite strong enough, is it? Well, I like to be diplomatic . . .