Can anyone help me fix this Javascript?

Asked

Viewed 69 times

0

The following error is being presented:

Uncaught Syntaxerror: Unexpected Identifier

on line 12. I would like someone to help me correct this mistake.


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(){

1 answer

7


  • Missing a comma after dataType: 'json',

  • Missing one n in the ready:function(){

  • On line 21 this here is the most:

        }};
    

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

Understand that when you pass an object, like the one you’re sending to vue, the syntax is basically this:

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

or in the case of value lists, arrays:

[ valor, valor, valor ]

and can combine the two things:

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

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.