Not Creating Objects | Javascript - Mobile APP | Visual Studio 2017

16 views
Skip to first unread message

daniel...@altatechimoveis.com

unread,
Mar 12, 2019, 4:29:42 PM3/12/19
to Back4App
Dear all,

Please, I need help!

I'm invoking a JS function to save some data from an HTML form, but it's not working.
Actually, it worked for a while and for some reason stopped working (maybe because of changes I've made on the app).

I also couldn't get the error message because of the syntax error " => " after save():

myNewObject.save().then(
(result) => {

Anyway, here goes part of the code:

HTML:
<head>

    <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com ; style-src 'self' ; media-src *; script-src 'self' https://npmcdn.com ; connect-src 'self' https://altatech.back4app.io ">

    <script src="https://unpkg.com/parse/dist/parse.min.js"></script>

</head>


JAVASCRIPT:
function gravaDadosTerreno() {
    
        Parse.serverURL = 'https://altatech.back4app.io';
        Parse.initialize('d0d...', 'cFP...');

        const DadosDoImovel = Parse.Object.extend('DadosDoImovel');
        const myNewObject = new DadosDoImovel();
    
        myNewObject.set('zonaDoImovel', sessionStorage.getItem("zonaDoImovel"));
        myNewObject.set('tipoImovel', sessionStorage.getItem("tipoImovel"));
        myNewObject.set('cidade', sessionStorage.getItem("cidade"));
        myNewObject.set('CEP', sessionStorage.getItem("CEP"));
        myNewObject.set('bairro', sessionStorage.getItem("bairro"));
        myNewObject.set('rua', sessionStorage.getItem("rua"));
        myNewObject.set('numero', sessionStorage.getItem("numero"));
        myNewObject.set('complemento', sessionStorage.getItem("complemento"));
        myNewObject.set('metragemTerreno', sessionStorage.getItem("metragemTerreno"));
        myNewObject.set('metragemAreaConstruida', sessionStorage.getItem("metragemAreaConstruida"));
        myNewObject.set('username', sessionStorage.getItem("username"));
        myNewObject.set('metragemAreaDescoberta', sessionStorage.getItem("metragemAreaDescoberta"));
        myNewObject.set('padraoDeConstrucao', sessionStorage.getItem("padraoDeConstrucao"));
        myNewObject.set('vagasDeGaragem', sessionStorage.getItem("vagasDeGaragem"));
        myNewObject.set('idadeConstrucao', sessionStorage.getItem("idadeConstrucao"));
        myNewObject.set('estadoConservacao', sessionStorage.getItem("estadoConservacao"));
        myNewObject.set('tipoTerreno', sessionStorage.getItem("tipoTerreno"));

        myNewObject.save();

}

 
Best regards.
Daniel

cha...@back4app.com

unread,
Mar 12, 2019, 7:10:49 PM3/12/19
to Back4App
Hi!

(Just checking) Have you already taken a look in our documentation?

Please, make sure that you're following the step 2 properly: https://www.back4app.com/docs/javascript/serverless-database

Also, are you facing any message error when you're trying to use this code?

Regards,
Charles Ramos

Em terça-feira, 12 de março de 2019 17:29:42 UTC-3, Altatech Imóveis escreveu:
Dear all,

Please, I need help!

I'm invoking a JS function to save some data from an HTML form, but it's not working.
Actually, it worked for a while and for some reason stopped working (maybe because of changes I've made on the app).

I also couldn't get the error message because of the syntax error " => " after save():

myNewObject.save().then(
(result) => {

Anyway, here goes part of the code:

HTML:
<head>

    <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com ; style-src 'self' ; media-src *; script-src 'self' https://npmcdn.com ; connect-src 'self' https://altatech.back4app.io ">

    <script src="https://unpkg.com/parse/dist/parse.min.js"></script>

 
Best regards.
Daniel
Message has been deleted

Altatech Imóveis

unread,
Mar 13, 2019, 3:56:31 PM3/13/19
to Back4App
Hi Charles!

Actually, I was following the API Reference from Parse Dashboard.

I followed step 2 from the documentation, but it also didn't work.

In both cases, I'm not getting any message error.

When debugging it, I could observe that doesn't enter the success or error, so there is no message in my console.

Find the new JS code below:

function gravaDadosTerreno() {
    
        Parse.initialize("d0d..."); //PASTE YOUR Back4App APPLICATION ID
        Parse.JavaScriptKey = "cFP..."; //PASTE YOUR JavaScript KEY
        Parse.serverURL = "https://altatech.back4app.io/";

        var DadosDoImovel = Parse.Object.extend('dadosDoImovel');
        //const myNewObject = new DadosDoImovel();
    
        create();

        function create() {
            const myNewObject = new DadosDoImovel();

            myNewObject.set("username", sessionStorage.getItem("username"));
            myNewObject.set("zonaDoImovel", sessionStorage.getItem("zonaDoImovel"));
            myNewObject.set("tipoImovel", sessionStorage.getItem("tipoImovel"));
            myNewObject.set("cidade", sessionStorage.getItem("cidade"));
            myNewObject.set("CEP", sessionStorage.getItem("CEP"));
            myNewObject.set("bairro", sessionStorage.getItem("bairro"));
            myNewObject.set("rua", sessionStorage.getItem("rua"));
            myNewObject.set("numero", sessionStorage.getItem("numero"));
            myNewObject.set("complemento", sessionStorage.getItem("complemento"));
            myNewObject.set("metragemTerreno", parseFloat(sessionStorage.getItem("metragemTerreno")));
            myNewObject.set("metragemAreaConstruida", parseFloat(sessionStorage.getItem("metragemAreaConstruida")));            
            myNewObject.set("metragemAreaDescoberta", parseFloat(sessionStorage.getItem("metragemAreaDescoberta")));
            myNewObject.set("padraoDeConstrucao", sessionStorage.getItem("padraoDeConstrucao"));
            myNewObject.set("vagasDeGaragem", sessionStorage.getItem("vagasDeGaragem"));
            myNewObject.set("idadeConstrucao", sessionStorage.getItem("idadeConstrucao"));
            myNewObject.set("estadoConservacao", sessionStorage.getItem("estadoConservacao"));
            myNewObject.set("tipoTerreno", sessionStorage.getItem("tipoTerreno"));

            myNewObject.save(null, {
                success: function (dadosDoImovel) {
                    console.log('Created successful');
                },
                error: function (response, error) {
                    console.log('Error: ' + error.message);
                }
            });
        }

        return;
}

Thanks for helping.

Daniel Garcia

cha...@back4app.com

unread,
Mar 14, 2019, 11:09:26 AM3/14/19
to Back4App
Hi Daniel,

Could you please send us your app ID?

Feel free to send it directly to us, our email address is comm...@back4app.com.

Regards,
Charles Ramos
Reply all
Reply to author
Forward
0 new messages