• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Code works on one host but not another

 
Greenhorn
Posts: 10
C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have recently moved web hosts and some Javascript that worked on my old host does not work on the new host. The getPattern method is responsible for initiating a file load by calling the getText method.
The console output indicates that the call to getResponceHeader(...) line 16 returns null which is unexpected behaviour. Any ideas / solutions welcome.


In line 9 it calls the getText method


Console Output
The .LIF files are simple text files storing cell position data for Conway's Game of Life

Get text Q7.LIF Type 16 lifepattern.js:32:3
Get text Q11.LIF Type 1 lifepattern.js:32:3
Ready state 2 status 200 httpget.js:21:4
Ready state 3 status 200 httpget.js:21:4
Ready state 4 status 200 httpget.js:21:4
Getting response header httpget.js:24:4
ResponseHeader null httpget.js:26:4
syntax error Q11.LIF:1:1
TypeError: type is null httpget.js:27:0
Ready state 2 status 200 httpget.js:21:4
Ready state 3 status 200 httpget.js:21:4
Ready state 4 status 200 httpget.js:21:4
Getting response header httpget.js:24:4
ResponseHeader null httpget.js:26:4
syntax error Q7.LIF:1:1
TypeError: type is null httpget.js:27:0
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the responses from both servers are identical, then the problem cannot be with changing hosts. Have you checked?

Why are you not using jQuery to do the Ajax? It's poor form to roll your own Ajax and cross-browser issues are going to (not may, are going to) bite you in the keester sooner or later, and likely sooner.

But to your current issue: first step is to compare responses.

 
Ranch Hand
Posts: 310
18
MS IE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Didn't you change the domain on which your application works? Cross-domain AJAX calls require a little more care to get them work.
 
Peter Lager
Greenhorn
Posts: 10
C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I cannot compare the responses from both servers because I have transferred my domain name and website to the new host and I can't access the old host servers.

It is not a cross domain issue because all the files are in the same domain (lagers.org.uk) and on the same host servers.

I am not using JQuery because I am totally new to JavaScript programming and this was my first serious JavaScript (learning) project.
 
Andrew Polansky
Ranch Hand
Posts: 310
18
MS IE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure that the web server on your new host produces the "Content-Type" header? Check that using using some web developer tools (like Firebug in Firefox or those built-in in Chrome).

Below is an example how it should look like in Firebug (Firefox):



I am not using JQuery because I am totally new to JavaScript programming and this was my first serious JavaScript (learning) project.


That's excellent that you are learning JavaScript without jQuery! Many people who are trying to learn JavaScript starts with jQuery right away, and later we see questions on StackOverflow like the famous "how to divide numbers in jQuery". jQuery is a great tool, but you should first know JavaScript well. Keep learning the JavaScript the "pure way" and you will learn it very well. Avoid third-party library until very necessary, during your learning path.

Bear mentioned that this code is going to have cross-browser issues, but as you are just learning, you don't have to worry about that for now.
 
Peter Lager
Greenhorn
Posts: 10
C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Adam thanks for the pointer towards Firebug it is interesting that my new host does not appear to produce the "Content-Type" header when trying to load the file. (See image) so I will revisit the code and do some experiments but any suggestions are appreciated.

 
Andrew Polansky
Ranch Hand
Posts: 310
18
MS IE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Indeed the server does not produce the "Content-Type" as you have observed. It happens because your web server does not know what mime-type should be set for .LIF files.

If you Apache server is configured with AllowOverride, you can create a .htaccess files in the directory where .LIF files are stored (or in root directory of your website), and add the following content:



Another way is to add file extension and mimetype association in Apache's mime.types file. That file should be somewhere in the Apache configuration directory. What you should add to this file is:



By looking at your code, I think that you expect the .LIF files to be plain text files. In that case, the mime-type you should set is text/plain.

Example for .htaccess:


Example for mime.types:


Note:
Editing .htaccess file does not require server restart, but editing mime.types does.
 
Peter Lager
Greenhorn
Posts: 10
C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Adam thanks for the additional info on mime-type I will investigate that further. In the meantime I have found a work around by simply removing the test for the Content-Type. I know this is not good practice but for the time being it will do. If you visit my website you will see the animation working.


Thanks guys.
 
Andrew Polansky
Ranch Hand
Posts: 310
18
MS IE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Verifying files by checking mime-type is not reliable. They don't reliably describe file content, it's just like a label on a closed box. The label can say your box has diamonds inside, but in reality it may contain potatoes.

Imagine that you have a web application that displays user uploaded JPG files. If you code your script to accept every file with mime-type "image/jpeg", somebody can easily spoof that mime-type and upload an executable file to your server.

The best way to determine what the file really is, is by checking it's content. In case of JPG files, you can check the file by checking the "magic byte" and for valid JPEG header.

In your case, if you want to check if the downloaded .LIF file is valid, I would simply check if the first line of the file equals to "#Life 1.05". A file with "text/plain" mimetype can be anything.

I took a look at your website, the animation looks great. This is impressive that you learn JavaScript and built such application without any third-party libraries. This is really great Peter, great work.
reply
    Bookmark Topic Watch Topic
  • New Topic