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
Related
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.
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
I have built a really simple script using JQuery/JSApi. I want to deploy it to my raspberry pi. As such, I need to make it only use the minimal amount of code possible (Pi is already full!).
It will not have a network connection, so let's say I just want to grab one file from the JSApi (as an example - I will not actually do this as it isn't legal).
So, I opened fiddler, opened my webpage, and saw what dependencies it had. After loading the JSApi, it fetched the following two files :
GET www.google.com/uds/api/visualization/1.0/69d4d6122bf8841d4832e052c2e3bf39/format+en,default+en.I.js HTTP/1.1
GET www.google.com/uds/?file=visualization&v=1 HTTP/1.1
So, two questions - firstly, is there any legal way for me to get this file and host it locally for JSApi?
Assuming no is the answer to this, let's assume the files are JQuery modules - where I believe this would be allowed. How would I grab them, and point to them locally? When I try to navigate to either of the addresses above, for example, I get an error message or nothing loads - so it is not possible to include these modules (or other JQuery modules) separately ?
Thank you!
I don't know if this will work in your exact setup, but you can do something like the following to get it pared down to the bare essentials:
Write up your webpage with the full jQuery package and any modules necessary (per your second example)
Pass all the javascript you're using through something like Google's Closure Compiler: https://closure-compiler.appspot.com/home
Include that compiled javascript, which will include only the absolutely necessary functions.
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
I've searched SO and have been unable to find this question asked before, but I can't believe I'm the only one running into it. If this is a duplicate, please point me to the original question.
In VS2008, I have some ASP.NET MVC markup in a script section on some of my pages. I end up getting "expected expression" warning squiggles on the ASP.NET MVC markup even though the jQuery/JavaScript in the preceding code is valid. It only happens on the markup.
This doesn't prevent the page from rendering, everything works fine. It is more an annoyance than anything else. I've installed VS2k8 SP1 along with the Intellisense hotfix and it still happens. It also happens whether I'm running R# 4.5 or the 5.0 EAP.
Suggestions or should I just pick my battles when it comes to VS 2008?
Screenshot: My apologies, I could have sworn I added a screenshot to this question.
http://www.twitpic.com/z6bxj
The VS designer is not good at handling cases where your markup jumps between server-side and client-side script.
Sometimes adding <%=""%> at the top helps, as per this post: http://forums.asp.net/t/1384577.aspx.
The VS designer also seems slow to pick up changes, re-parse and remove error squiggles.
In your case I think it's trying to parse that line as Javascript but it's obviously not. If you're nuts about removing the errors you would have to re-factor the code, eg generate the entire JS script as a server-side string and write it out.
I've learned to view error squiggles as advice only, and once the page is stable and working just ignore them.