-2

Goodmorning folks!

I've been testing my JavaScript code via the Google Chrome developer console, and fixed all of the errors, except one that says,"Uncaught SyntaxError: Unexpected token :" I found similar questions on Stack Overflow, but my situation is different. In addition, usually when the console lists the error, it would have provide a link to view the error, which would be underlined in red. However, this time the console lists the error, but doesn't underline, in red, the wrong part of the code.

Screen-shot of Google Chrome Developer Console Displaying Error

To me everything looks formatted correctly, and all my double colons look correctly placed. Are you able to help? Thanks in advance!

Here is my JavaScript code:

$(document).ready(function(){ 

//when search is clicked run code
$(search).on('Click'(function(){

//gets search input
var searchTerm= $("#searchTerm").val();

//API url with searchTerm
var url="https://en.wikipedia.org/wiki/Special:ApiSandbox#action=query&titles=Main%20Page&prop=revisions&rvprop=content&format=jsonfm";

//create an AJAX call within .on("Click") function
$.ajax({})
    //We intend to do a GET call (because we are retrieving data from the server)
    type: "GET"
    url: url,
    //code will be paused while other code waiting for this to finish
    Async: false,
    dataType: json,
    Success: function(data){ 
    //How will you test for success of json call function
    console.log()data;  
},

//Do something when its a function and do something else when it's a failure
Error: function(errorMessage){
    //Console out a warning that says something like "error" alert
    alert("Error"); 
}


}); //search

});//document ready
codebwoy
  • 145
  • 3
  • 20
  • 1
    Line numbers in the error will help you debug it in future. – a-- Jan 16 '18 at 17:27
  • @MorganLane, line numbers? I have that in my text-editor.... – codebwoy Jan 16 '18 at 17:31
  • `$(search).on('Click'(function(){` <-- that ain't right – epascarello Jan 16 '18 at 17:33
  • and `console.log()data;` ain't right.... – epascarello Jan 16 '18 at 17:34
  • @epascarello, how are these not right? Can you explain? – codebwoy Jan 16 '18 at 17:35
  • and missing comma.... so far 3 things wrong with "well formatted code" – epascarello Jan 16 '18 at 17:35
  • you can not see the issue with those? – epascarello Jan 16 '18 at 17:36
  • @epascarello, can't the click function be written as `$('#search').click(function(){ } or as `$(search).on('Click'(function(){ } ` ...........??? – codebwoy Jan 16 '18 at 17:38
  • 1
    yes, but you can also use on, if you do it the right way. It has two issues. Case matters and it is missing a comma. Other one is also pretty obvious. Any good linter would pick these up. Look at the examples for on.... http://api.jquery.com/on/ – epascarello Jan 16 '18 at 17:40
  • @epascarello, ok, I see the case issue, but where is the missing comma? I also just fixed the `console.log(data)` issue.....it should be `console.log (data)`....And how come the console isn't showing all these errors that you've pointed out? That's weird to me.... – codebwoy Jan 16 '18 at 17:42
  • 1
    The parser stops when it sees the error. Look at the link I posted to the jQuery docs for `on` and compare it to what you have. – epascarello Jan 16 '18 at 18:01
  • 1
    and the Ajax line is wrong.... just noticed that... Properly indent your code and you can spot these issues. Use a linter like jshint http://jshint.com/ or eslint, jslint, etc. – epascarello Jan 16 '18 at 18:03
  • @SudiptaKumarMaiti, I saw the error that @epascarello pointed out in AJAX.... and `console data`....I don't need the unpolite-ness of "please code properly", if people could all code properly, Stack Overflow would not exist! – codebwoy Jan 16 '18 at 18:08
  • 1
    @codebwoy Basically you really should learn to use your tools to help you spot your issues. Your code not being properly indented does not help. Integrate a linter into your IDE so it helps to enforce good practices. – epascarello Jan 16 '18 at 18:27
  • @epascarello.....I agree....I'm also a JavaScript newbie, and have designed a couple successful web apps with JavaScript, but due to always being in a rush, I don't always retain what I learn well lol....and where can I learn how to integrate a linter into my IDE?...I use a Sublime text-editor....infact, is Sublime an IDE? – codebwoy Jan 16 '18 at 18:36

1 Answers1

3

You are missing , after type: "GET"

Prerak Sola
  • 9,517
  • 7
  • 36
  • 67