2014-02-27 97 views
0

我正在使用Crossrider创建Chrome扩展(Add-On's)。我在这里做的是调用检索JOSN数据的wcf服务(2列10行)。数据正在通信,但是当我在crossrider数据库中插入此JSON数据时显示Errror(错误代码405)。我完全是在crossrider Async.db Demo中完成的。以下是我的代码插入JSON数据到Crossrider数据库显示错误

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); 
         }); 
}); 
+0

检查数据为了帮助您,请提供一个真正的代码片段相关的URL和回调函数。这将使我能够帮助您解决您的问题。 [**披露**:我是Crossrider员工] – Shlomo

+0

假设错误代码是一个HTTP错误,[405是方法不允许](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_Error)aka使用a当服务器仅支持POST时GET。 – abraham

+0

@abraham对错误消息是正确的,但是您声称已收到数据。哪个回调被触发,成功或失败?另外,如果你想让我看看这个问题,你必须为'检索JSON数据的URL'提供一个有效的URL,以便我可以测试这个场景。 – Shlomo

回答

2

最后我做了另一个过程来将JSON数据插入到crossriderDB。 步骤:1)使用appAPI.request.post我得到的JSON数据并解析JSON数据

 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' 
}); 

步骤:2)这是JSON数据插入到数据库的代码中,我在函数写了这个代码而这个功能是从上面的代码

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

步骤调用:3)从数据库

appAPI.db.async.get("StoredUrls",function(value){ 
if(value===null || value===undefined){ 
alert('no data'); 
} 
else{alert(value);} 
}); 
+0

感谢您的更新。你抢先了我的下一步,我很高兴看到你设法自己得出同样的结论;-) – Shlomo

相关问题