JavaScript doesn't work on localhost - javascript

First, excuse me if my English is not completely right, as I am Dutch.
I'm busy working on a project. Since a short time, I get some errors in my console when I'm checking the website on my localhost. I'm using USB Webserver, but I had the same problem when I was using WAMP.
The strangest thing is, that the website is working on my live server, without errors.
The errors I get in my console on localhost are:
Uncaught SyntaxError: Invalid or unexpected token
Uncaught ReferenceError: jQuery is not defined
I know that, according to the second error, it might be a problem with the order in which the files are placed, but I have done that in the way it was done by the creators of my template.
The only thing I have done, is combining all the JavaScript files and minify them.
When I go to the source code on my live server, there's nothing wrong with the JavaScript code. But when I open the source code on my localhost, I get wrong symbols in the code, that's breaking up the actual code.
One line:
retÀ‚ã����À‚ã��������������������P‡Ê������������`ŸÊ����(ƒã������������à‚ã�����#������à‚ã������������idden"
The charset in my html is set to utf-8. I hope you guys can help me out! :)
If you need more information, just let me know.

Well,the first error in your console is exactly indicating that somewhere in your code has a syntax error.
You said your "html is set to utf-8",you might put the javascript code in the html.Make a try to separate it into a single file.

Related

ReferenceError: document is not defined (JavaScript in VS Code)

Im learning JS. Found a good video "JavaScript Programming - Full Course" and stucked at the 2nd part where I need to use DOM. I have the HTML document, in i refered to the JS file. Other stuff working well, but this:
let messageEL = document.getElementById("message-el")
Always get this error:
ReferenceError: document is not defined
I installed live server, and it works one time, than stops.
What can I do, to fix this? Do I need to download some extension?
Please tell me the solution as simple as u can Im at the beginning of the learning path.
This is the code and the error
In your screenshot, you're attempting to run the script using Node.js (the server-side JavaScript executable).
Since you say you're running live-server, you should be looking at your browser instead, not trying to run your code via Node.

Saving javascript script output to file on server

So far Gurus here helped me a lot so far and I am back again with my little queries again.
I have a js that is being called from a webserver through a internal site I am taking care of. js has lots of very helpful debugging comments through
console.log($output)
that are being displayed on the console. I was wondering if there is any way i can redirect these comments to a log file on server.
I know it is hard but not impossible... I thought of doing something like
> exec 1>>${LOG_FILE}
but then it means it will get outputs from every file will be going to that file.
I only need the output from one file... is it possible?? plus do I need to run it through cron? because I don't have permission to change anything in js itself.
-Thanks

Having troubles opening relative URL in Javascript xmlhttp object

I've inherited an HTML/PHP/Javascript application that is not broken up in specific directories; meaning, everything was in one directory.
I want to clean up and modularize the directory structure, so, I moved everything.
(*.inc files moved to the "Includes" folder, *.css files moved to the "CSS" folder, etc.)
Naturally, there is some changes to the code to be made.
I was making a (Working) AJAX request like this:
xmlhttp.open("GET","oWin.php?name="+escape(name)+"&type="+ct,true);
where "oWin.php" resided in the same directory as the calling page. oWin.php is now located two directories up in the "Lib" folder. So, I needed to change it to this:
xmlhttp.open("GET","../../Lib/oWin.php?name="+escape(name)+"&type="+ct,true);
but, sadly, this does not work; I get a "Syntax Error" logged to the web console in FireFox.
Can someone shed some light on this as to why it is a syntax error?
FireFox version 30.0
Windows version 7, 64 bit
Apache 2.2.4, Win32
PHP 5.2.3
Thanks!
Keith
UPDATE
I've moved the oWin.php file into the same directory as the calling script and I am STILL getting a syntax error! There MUST be some kind of error being returned from oWin.php....I will update as I discover more!
UPDATE AND ANSWER
Since I can't answer my own question yet (not 8 hours later and I'm a noob here) :(
The REAL reason I was getting an error was not because of a syntax error in the Ajax call, but rather, what was getting PASSED back from oWin.php to the Ajax call.
I installed FireBug addon to help (I should have done that sooner) and had a look at the xml response.
I had PHP warnings enabled and was receiving a warning (didn't realize it) and so the PHP warning was getting passed to the Javascript interpreter via the AJAX call....so, naturally, the JS interpreter is going to throw an error!
Sorry for the noob mistake!
Thanks to everyone who read and responded!
Keith
The REAL reason I was getting an error was not because of a syntax error in the Ajax call, but rather, what was getting PASSED back from oWin.php to the Ajax call.
I installed FireBug addon to help (I should have done that sooner) and had a look at the xml response.
I had PHP warnings enabled and was receiving a warning (didn't realize it) and so the PHP warning was getting passed to the Javascript interpreter via the AJAX call....so, naturally, the JS interpreter is going to throw an error!
Sorry for the noob mistake!
Thanks to everyone who read and responded!
Keith

Why would my server not properly link to only one file on the server, but fine on all the others?

I originally posted this question on the code review forum, but was directed back to StackOverflow.
One contributor said that it was a problem with my Apache/server setup, but why only is one .js file affected? Problem described here:
I am a bit of a jQuery raven, I learn and take as needed forage about, and have no formal education, so your patience is appreciated.
I have a main issue that a jQuery plugin is not working on the server, but works locally.
I have checked for the usual oversights (having relative links not on the server, having all the required files on the server & case sensitivity issues), but it still wouldn't work.
I am not fluent in the FireFox debugging tools either, however I found a enormous anamoly which I suspect is causing the issue.
The plugin code is in it's own .js file, and in the "debugger" in firefox, when I click on the appropriate file, instead of previewing the .js file, it shows me the index PHP/HTML of the root for the domain.
For specific, real examples:
Example page where the plugin is failing: Here
Here are the error messages that I get under the "Console" tab in FireFoxe's tools:
SyntaxError: syntax error # http://bcw.se/3point0/js2013/imageScroller.js:1
TypeError: $(...).tinyscrollbar is not a function # http://bcw.se/3point0/index_debug_crousel_02.html:75
Use of Mutation Events is deprecated. Use MutationObserver instead. # http://code.jquery.com/jquery-latest.js:3492
And I presume the first two errors above are due to the anamoly and causing the failure, not directing properly to the right .js file, see screen dump below:
Can anyone help and is this the right forum?
Thanks in advance.
Your file is called ImageScroller.js and not imageScroller.js. Change that and it should work. (Apache should be case sensitive)
As imageScroller.js doesn't exist the url gets rewritten to the index page (probably by your .htaccess RewriteRule).
And the origin of the syntax error is kinda obvious - The browser tries to parse the fetched "js" file as JavaScript. But just isn't valid JavaScript ;).
Sincerely
Louis

Problem porting WordPress Editor to a non-WP application

I like the look and feel of the WordPress editor (version 2.7), and I would like to use it in another web application that is written in ASP.NET. I've used TinyMCE before, and I've even extended it in the past. However, I can't seem to get the Wordpress configuration to work!
I've downloaded the entire WordPress package and taken the TinyMCE code (from the "js" folder) and put it in my web site. It ends up giving me an error on the following line of tiny_mce.js
return f.apply(s||this,Array.prototype.slice.call(arguments,2))
'undefined' is null or not an object.
Now, I've carefully made sure that the steps of execution are identical with the WordPress demonstration site that I've based this from.
I'm not a Javascript newbie (at all), but I can't seem to figure out why this is not working. Has anybody tried to do this before? What am I missing?
A demo of what I am talking about is here (username="admin", password="demo"). View the source, I have the three parts of Javascript that are (seemingly) required to power the editor.
Something of a stab in the dark, but I'm suspecting that there's a dependency on WP's prototype.js and you didn't bring that over with TinyMCE.
If you are able to determine which bit is undefined that might give you a clue. I tried looking at the demo with firebug, but tinymce.js was all one line, so I gave up trying to find that code.
Try putting in either some console.log() if you have firebug, or alert()s before that line, and try to see what f,s,this,arguments etc are when yu get the error, then do the same thing with a vanilla WP install and see the difference?
I suggest including the tiny_mce_src.js istead of the minified version, this way you can use firebug to debug and receive helpfull information.

Categories

Resources