Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

jQuery and object database error (storing info in database)

Replace
codedata: {"filename": filename},/code
with the following:
codedata: JSON.stringify( {"filename": filename} ),/code

Anna G.
Posts: 0
Joined: Fri Jun 21, 2013 2:08 pm

jQuery and object database error (storing info in database)

Hi Katya,

I replaced the first code with the second and now I get a different error: {"code":"DBSC216","description":"Emptyobjectscan'tbecreated.Pleasespecifyatleastonefield."}.

We also added an alert for the stringify function and it gave us the correct output.

codevar file;
function fileSelectHandler(e) {
var files = e.target.files || e.dataTransfer.files;
file = files[0];
previewFile();
}

function userData(filename) {
alert( JSON.stringify( {"filename": filename} ) );
var url = 'https://api.appery.io/rest/1/db/collections/things/';
$.ajax({
type: "POST",
beforeSend: function(request) {
request.setRequestHeader("X-Appery-Database-Id", "51c1d0bde4b0d0a692ef56b1");
request.setRequestHeader("X-Appery-Session-Token", localStorage.getItem('token')),
request.setRequestHeader("Content-Type", "application/json");
},
url: url,
data: JSON.stringify( {"filename": filename} ),
processData: false,
success: function(html) {
alert("it worked");
},
failure: function(html) {
alert("it didn't work");
}
});
}

function upload() {

Code: Select all

 var serverUrl = 'https://api.appery.io/rest/1/db/files/' + file.name.replace(/ /g, "_"); 

 $.ajax({ 
     type: "POST", 
     beforeSend: function(request) { 
         request.setRequestHeader("X-Appery-Database-Id", "51c1d0bde4b0d0a692ef56b1"), 
         request.setRequestHeader("X-Appery-Session-Token", localStorage.getItem('token')), 
         request.setRequestHeader("Content-Type", file.type); 

     }, 
     url: serverUrl, 
     data: file, 
     processData: false, 
     contentType: false, 
     success: function(html) { 
         // upload successful 
         $(".content").html(html); 
         $('#success').show(); 

         userData(html.filename); 
      }, 
     error: function(html) { 
         // upload unsuccessful 
         $(".content").html(html); 
         $('#error').show(); 

}
});
}

function previewFile() {

Code: Select all

 var previewContainer = $('table[dsid=preview]'); 
 var fileName = $('[name=fileName]'); 
 // make the preview container visible once a file was selected 
 previewContainer.toggle(); 

 // set the file name 
 fileName.text(file.name); 

 // display image in preview container 
 if (file.type.indexOf("image") == 0) { 
     var reader = new FileReader(); 
     reader.onload = function(e) { 
         var image = $('[name=image]'); 
         image.attr('src', e.target.result); 
         $('[class=mobileimage1_div]').show(); 
     } 
     reader.readAsDataURL(file); 
 } 

}/code

Anna G.
Posts: 0
Joined: Fri Jun 21, 2013 2:08 pm

jQuery and object database error (storing info in database)

Is there any way to fix this new error?

Thanks,
Anna

Anton Artyukh5836028
Posts: 0
Joined: Wed May 08, 2013 12:57 pm

jQuery and object database error (storing info in database)

Hi Anna,

I'm sorry for the delay.

What are you seeing in the alert( JSON.stringify( {"filename": filename} ) );?

Do you have field 'filename' in your collection?

Anna G.
Posts: 0
Joined: Fri Jun 21, 2013 2:08 pm

jQuery and object database error (storing info in database)

Hello Anton,

That's completely fine - I just wanted to make sure the topic didn't get buried!

The alert gives {"filename":"nameoffile.jpg"} with "nameoffile.jpg" being the name of the file in the database.

No, we didn't. We didn't know we had to. But this fixed our error!!! Thank you so much for your help (Anton and Katya)!

Thanks again,
Anna

Asif
Posts: 0
Joined: Tue Aug 13, 2013 12:56 pm

jQuery and object database error (storing info in database)

Hi
I am also getting same error
code":DBSC007", "description":"serializationerror

I am trying to access a rest service of Appery form Google Chrome rest client

This is my service url : https://api.appery.io/rest/1/db/colle...

I am providing data base id over there but not the session id because it is not required for a collection.

Pls help!

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

jQuery and object database error (storing info in database)

Hi Asif,

Do you try on preview on on service Test tab? Do you use our proxy?

Asif
Posts: 0
Joined: Tue Aug 13, 2013 12:56 pm

jQuery and object database error (storing info in database)

Hi Katya,
I tried it on Appery service test tab, it is working fine from there with the same parameters and same settings. I am not using Appery.io proxy

Asif
Posts: 0
Joined: Tue Aug 13, 2013 12:56 pm

jQuery and object database error (storing info in database)

when i am doing a GET operation it is working fine from Google chrome rest client, but it is failing when i m selecting POST option

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

jQuery and object database error (storing info in database)

Asif,

Please post a screenshot of your Chrome REST client where we can see a request itself.

Return to “Issues”