开发者

JavaScript working differently locally than online

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 s开发者_如何学Pythonerver 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.


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜