Search code examples
node.jspug

PUG Unexpected text


I had to convert a jade file to pug format. I managed to correct some of the errors, but I block on this one:

> Error: C:\Users\Asus\Desktop\cours_nodejs\views\expressO1.pug:19:20
>     17|             $.get('/hello/', + $('[name=name]:checked').val(),
>     18| function(data) {
>   > 19|                    $('#message').html(data.message);
> ---------------------------^
>     20|                }, 'json' );
>     21|           }
> 
> unexpected text "$('#m"
>     at makeError (C:\Users\Asus\Desktop\cours_nodejs\node_modules\pug-error\index.js:32:13)
>     at Lexer.error (C:\Users\Asus\Desktop\cours_nodejs\node_modules\pug-lexer\index.js:59:15)
>     at Lexer.fail (C:\Users\Asus\Desktop\cours_nodejs\node_modules\pug-lexer\index.js:1441:10)
>     at Lexer.advance (C:\Users\Asus\Desktop\cours_nodejs\node_modules\pug-lexer\index.js:1501:15)
>     at Lexer.callLexerFunction (C:\Users\Asus\Desktop\cours_nodejs\node_modules\pug-lexer\index.js:1456:23)
>     at Lexer.getTokens (C:\Users\Asus\Desktop\cours_nodejs\node_modules\pug-lexer\index.js:1512:12)
>     at lex (C:\Users\Asus\Desktop\cours_nodejs\node_modules\pug-lexer\index.js:12:42)
>     at Object.lex (C:\Users\Asus\Desktop\cours_nodejs\node_modules\pug\lib\index.js:99:27)
>     at Function.loadString [as string] (C:\Users\Asus\Desktop\cours_nodejs\node_modules\pug-load\index.js:44:24)
>     at compileBody (C:\Users\Asus\Desktop\cours_nodejs\node_modules\pug\lib\index.js:86:18)

Despite my research, I failed to understand what was causing this error (nor to find a solution to solve it). Here is the code of the pug file:

doctype html
head
 title=theTitle
 body
   div Choisir unprenom :
   - for name intheNames
     label
      input(type="radio", name="name", value=name)
      spanPrenom : #{name}
     br
   div
      input(type="button", onclick="valid()",value="OK")
      #message
      script(src="http://code.jquery.com/jquery-1.10.1.min.js")
      script.
         function.valid() { 
            $.get('/hello/', + $('[name=name]:checked').val(),
function(data) {
                   $('#message').html(data.message);
               }, 'json' );
          }

Thank you for your advice !


Solution

  • you have to indent the function(data) { line under the $.get('/hello/', + $('[name=name]:checked').val(),

    i hope i helped

    doctype html
    head
     title=theTitle
     body
       div Choisir unprenom :
       - for name intheNames
         label
          input(type="radio", name="name", value=name)
          spanPrenom : #{name}
         br
       div
          input(type="button", onclick="valid()",value="OK")
          #message
          script(src="http://code.jquery.com/jquery-1.10.1.min.js")
          script.
             function.valid() { 
                $.get('/hello/', + $('[name=name]:checked').val(),
                   function(data) {
                       $('#message').html(data.message);
                   }, 'json' );
              }