Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. Collection.prototype.storeOfflineData = function(collectionId){
  2. var formData = new FormData($('form')[0]);
  3. pendingSites = {"collectionId" : collectionId, "formData" : formData};
  4. window.localStorage.setItem("offlineSites", JSON.stringify(pendingSites));
  5. Collection.prototype.goHome();
  6. Collection.prototype.showErrorMessage("Successfully store data in offline.");
  7. }
  8.  
  9. Collection.prototype.pushingPendingSites = function(){
  10. pendingSites = JSON.parse(window.localStorage.getItem("offlineSites"));
  11. if(pendingSites != null){
  12. console.log(pendingSites[i]["formData"]);
  13. Collection.prototype.ajaxCreateSite(pendingSites[i]["collectionId"], pendingSites[i]["formData"]);
  14. }
  15. }
  16.  
  17. Collection.prototype.ajaxCreateSite = function(collectionId, formData){
  18. $.ajax({
  19. url: '/mobile/collections/' + collectionId + '/sites', //Server script to process data
  20. type: 'POST',
  21. success: function(){
  22. Collection.prototype.goHome();
  23. Collection.prototype.showErrorMessage("Successfully saved.");
  24. },
  25. error: function(data){
  26. Collection.prototype.showErrorMessage("Save new site failed!");
  27. },
  28. data: formData,
  29. cache: false,
  30. contentType: false,
  31. processData: false
  32. });
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement