0

I've noticed that some simple scripts in JavaScript that work perfectly on my local server don't work at all online.

How can be this possible? JS client-side scripting? Any ideas?

Sorry for not providing much information, and for my English, too.

Mine was a general question.

For example:

$('#posticipa').click(function(){
    var stato = $('#future').css('display');
    if(stato == 'none'){$('#future').css('display', 'block');}
    else{ $('#future').css('display', 'none');}
});

This piece of code works perfectly on my local Apache server on Ubuntu 9.10, with Firefox 3.6, 3.5, Google chrome and Opera.

When I upload it on my remote CentOS server, also running Apache, it doesn't work. No errors are displayed in Firebug or the console; it just doesn't run.

I'm using the same version of jQuery on both servers.

6
  • 1
    To be clear you are talking about "in the browser" js not something like node.js? Commented Feb 2, 2011 at 15:05
  • 1
    If you post your code, it will be a lot easier to help. Commented Feb 2, 2011 at 15:06
  • What server are you using, and by which JS engine is it powered? What version of Javascript? What browser(s) are you using? What error are you getting? What objects are you using? You’re not exactly giving us a lot to work with. Commented Feb 2, 2011 at 15:12
  • sorry I provided more information Commented Feb 2, 2011 at 15:54
  • @PurplePilot i cant understand your question I have not wrote "in the browser" Commented Feb 2, 2011 at 15:56

3 Answers 3

2

Check console in your browser for errors. If it is Firefox - install firebug, if it chrome - press Ctrl + Alt + J.

Sign up to request clarification or add additional context in comments.

2 Comments

check out network tab. did your javascript load? if yes, set breakpoint on function that doesn't work.
tnx for the tip I didnt know the breakpoint function, well at the end is I change display to visibility properties all work fine. But actually I still can understand why this pass using display none or visibility hidden should be relative to the browser and not to the server
1

It depends on what your script is trying to do. "Any ideas?" is pretty broad. But client-side scripting has a lot more restrictions than server-side, for obvious security reasons. For example, if you could access the client's file system through client-side JS, any website on the internet would be able to take control of your system.

JavaScript Security Restrictions

1 Comment

you right, I just was trying to modify css properties of a div
0

Having looked at your edited question, I think it's most likely that one of two things is happening:

  • Some kind of error is causing the JS to fail before this code is hit (but you say FireBug isn't displaying an error, so if you've got FB set up right this shouldn't be the problem)
  • The entire script is never getting hit, probably due to an incorrect src attribute in the script tag.

Try putting a debugger; line or an alert somewhere very early in your JS code. That should tell you whether the script is getting hit (the debugger command should tell FireBug to go into debug mode, provided you have FB's Script tag enabled on when you load the page).

If it isn't getting hit, make sure the script's src is the correct, reachable URL. If it is, move the line steadily down your code until it doesn't fire anymore. That should help you figure out where the error is.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.