Question

I am Creating Chrome Extension(Add-On's) using Crossrider.What I am doing here is Calling wcf service which retrieve JOSN Data(2 columns with 10 rows). The data is commming but when I am inserting this JSON data in crossrider DB is showing Errror (Error Code 405). I was exactly done what was in crossrider Async.db Demo. The below is my Code

appAPI.ready(function($) {
appAPI.db.async.setFromRemote('Url which retrieves JSON Data',    // The url for the request
                        'URLs',            // The database key name
                        appAPI.time.daysFromNow(7),  // optional: expiration
                        function(response) {         // optional: success callback
                          alert(Successfully saved.');
                        },
                        function(status) {           //optional: failure callback
                          alert('Failed  error code: ' + status);
                        });
});
Was it helpful?

Solution

Finally I done another process to Insert JSON data to crossriderDB. Step:1) Using appAPI.request.post I get the JSON data and Parse the JSON data

     appAPI.request.post({

    url: 'http://localhost:3706/Service1.svc/json/GetAffiliatedUrlsCollection',
    onSuccess: function(response){
   var site = appAPI.JSON.parse(response);//Parse the JSON Data 
    alert(response);
    AddUrlToDB(site);//Calling function to Insertdata to db and passing Parsed JSON data
    },        
    onFailure: function(httpCode) {
        alert('Failed to retrieve content. (HTTP Code:' + httpCode + ')');
    },
    additionalRequestHeaders: {
        myHeader: 'value'
    },
    contentType: 'application/json'
});

Step:2) Here is the Code to insert JSON data to DB, I wrote this code in the function and this function is calling from the above code

    function AddUrlToDB(site){
appAPI.db.async.set("StoredUrls", site, appAPI.time.hoursFromNow(12),
    function() {
        alert("Successfully saved key-value pair to the local database");
    });
}

Step:3) Check the data from database

    appAPI.db.async.get("StoredUrls",function(value){
if(value===null || value===undefined){
alert('no data');
}
else{alert(value);}
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top