Can anyone help me to correct this JavaScript? [closed]

-1

The following error is displayed:

  

Uncaught SyntaxError: Unexpected identifier

on line 12. I would like someone to help me fix this error.


The JS is as follows:

document.addEventListener("deviceready",onDeviceReady,false);
function onDeviceReady(){
var vm = new Vue({
        el: '#app',
        data:{
            noticias: []
        },
        methods:{
            sync:function(){
                $.ajax({
                    dataType: 'json'
                    url: 'http://yhsoftware.esy.es/read.php',
                    success:function(dados){
                        localStorage.setItem('noticias',JSON.stringify(dados));
                        vm.setNoticias();
                        alert("lista de noticias atualizada!");
                    },
                    error:function(){
                        alert("ocorreu um erro durante a conexão com o servidor!");
                    }
            }};
        },
        setNoticias:function(){
            this.noticias = JSON.parse(localStorage.getItem('noticias'));
            console.log(this.noticias);
        }
    },
    ready:fuction(){
    
asked by anonymous 19.11.2016 / 22:39

1 answer

7
  • Missing comma after dataType: 'json',

  • n is missing in ready:function(){

  • On line 21 this here is more:

        }};
    

The correct nesting does not know, it depends on the end of the code.

Understand that when you pass an object, such as the one that is sending to vue , the syntax is basically this:

{ "nome1":"valor", "nome2":"valor" }

or in the case of lists of values, arrays:

[ valor, valor, valor ]

and can combine both:

{ "lista": [ 1, 2, 3 ], "objeto": { "a":1, "b":2 }, "funcao":function(){...} }

Note that values and pairs are always separated by commas. You will only get ; when the whole statement is finally over.

Note: If you paste the code into CODEPEN , for example, it already warns all this to you (an exclamation in red appears, that when clicked, shows the line with problem). It is more appropriate than bringing error correction here.

    
19.11.2016 / 22:42