Adam McMahon
Adam McMahon

Reputation: 413

javascript not working on localhost

Ok so I'm lost here, frustrated and pulling my hair and out. Plus probably about to be fired or take a pay cut.

I moved Files from a development server to my local machine. The files are consistent (used diff tool), all the dependencies are there. It works for the most part. The problem is that the some of the javascript (not all) is just not working. We're using jquery and a lot of plugins for it. I've checked with the web developer plugin in firefox and all the js files are loading. I cleared the cache in both firefox and chrome multiple times to no avail. The development server is a windows server running wamp. My local machine is running ubuntu. Somebody tell me what I missed.

Upvotes: 4

Views: 23713

Answers (5)

Tony Ringer
Tony Ringer

Reputation: 21

You may need to host the site using a local server. VS IDE has an add-on called live server. You need to set up a workspace in order for it to work. The port used on my machine was 5500.

You need to make sure any dependencies for javascript are running on your server or the javascript will not be executed. These dependencies are listed in the json file.

ex. If you require express, you need to be running node or the javascript won't execute in your web browser.

In the terminal: node app.js

Any dependencies that are not installed and running on the server will not execute.

Upvotes: 1

rmurphey
rmurphey

Reputation: 552

Are you running the files via a webserver, or just opening the files directly? If it's the latter, you'll want to set up a server on your local machine for local testing, and serve the files using it. Otherwise, you'll very likely run into the domain restrictions others have mentioned above.

Upvotes: 1

DaveG
DaveG

Reputation: 301

Download firebug as a Firefox extension and view the http request and responses. Easiest may be from within the 'net' tab to determine if your script is making a request.

Very likely that it is a source domain issue. There are no work-around for this issue. The ajax request and the source data must be on the same domain.

Upvotes: 5

rtpHarry
rtpHarry

Reputation: 13125

Are you accessing the html web pages through the webserver and not simply double clicking the file to open it?

Also if you have WebDeveloper toolbar installed the click "Disable", "Disable Javascript" and make sure "All Javascript" isn't ticked.

Upvotes: 0

cbednarski
cbednarski

Reputation: 11813

It may have something to do with JavaScript's security limitations. (In certain circumstances) You can only operate on URLs or pages from the current domain, which most likely changed when you moved the files off the other server. More here.

Upvotes: 2

Related Questions