Yuuza
Yuuza

Reputation: 179

"Illegal character" in the jQuery library file, even without an invisible character or a missing quote anywhere

What I'm trying to do

I'm programming a currency converter, and to not have to manually update the current currency, I get the current value from another website trough AJAX and Whatever Origin (to allow access to another domain). I tested it in a separated page and it worked perfectly, i.e. showed the current currency. However, when I inserted it in the actual code of the converter ...

The error

... any console accuses illegal character inside the jQuery file, even if I link to Google's library:

SyntaxError: illegal character            jquery.min.js:1:4  
ReferenceError: $ is not defined          Converter.html:75:0

Wherever I put it (in the beginning, middle or end), the same error happens, but only if I insert my code there, if I only link the jQuery file, no errors are showed.

The code

$.getJSON('http://whateverorigin.org/get?url=' + 
    encodeURIComponent('http://usd.fx-exchange.com/brl/') + '&callback=?',
    function (data) {
        currency = $('.today_s', data.contents).html();
        currency = currency.match(/\d\.\d\d\d\d/);
});

The page I'm trying to move to: here.

The working test page: here.


I don't even have a clue of what is happening..

Upvotes: 5

Views: 1417

Answers (2)

Yuuza
Yuuza

Reputation: 179

After many tweaks, finally I got rid of that error! What I did:

First I moved the contents of the actual page to the test page. Then I moved my script to a separated .js file. Then the error accused "illegal character" for arithmetic symbols (/ and *) in the functions in the beginning of the file. So I moved them to the end. Then I moved the jQuery code to the beginning of the .js file. Then finally I got free! =D

I don't know what was the real error, the only things I know is that it wasn't an "illegal character", and doing what I did fixed that.

By the way, thanks for the attention to who tried to help, even though.

Upvotes: 2

T McKeown
T McKeown

Reputation: 12847

Verify your js link and you should run your jQuery code once jquery is loaded:

$(document).ready( function() {

 $.getJSON('http://whateverorigin.org/get?url=' + 
encodeURIComponent('http://usd.fx-exchange.com/brl/') + '&callback=?',
function (data) {
    currency = $('.today_s', data.contents).html();
    currency = currency.match(/\d\.\d\d\d\d/);
   });
});

Upvotes: 0

Related Questions