vendredi 8 mai 2015

Chrome extension to send data to a webpage

I want my chrome extension to send a data to my web application based on node.js 's controller . Like done in this question Submitting Ajax request to node.js controller .I have used ajax call to send data and the call is successfull but i don't know how to how to pass that url being sent as a parameter to nodejs app controller.

Here is my code.

google_helper.js file that is sending data.

$("body :not(#prospector-modal)").on("click", "a.add-to-prospector",function(event){
var that = this;
event.preventDefault();
event.stopPropagation();
console.log('adding');
fetchable = $(that).data('target');
console.log("fetchable " + fetchable.description);
console.log("fetchable " + fetchable.url); //this is the url that i have to send


$.ajax('http://ift.tt/1GUXMEg', {

          headers: { 'Content-Type': 'application/json'},
          data: JSON.stringify({fetchables: [fetchable] })
      })
      .done(function (data, textStatus, xhr) {
          debugLog("POST.done");
          debugLog(xhr);
          $(that).replaceWith("<span class='prospector-added'>Added!</span>");
          initOrReinit();
      })
      .fail(function (xhr, errorMessage, error) {
          debugLog("POST.fail");
          debugLog(xhr);
          if( xhr.status == 401 ) {
              displayErrorSalesLoftLoginModal();
          } else if (xhr.status == 429) {
            displayErrorLimitModal();
          } else {
            displayErrorModal();
          }
      });

});

When i am making request it is going in .done part of ajax call.

background.js

 var Fetchable = function(data) {
  this.data = data;
 };

Fetchable.prototype = {

 fetch: function(delay_milliseconds) {
var self = this;
$.get(this.data.url)
.done(function (data, textStatus, xhr) {
  debugLog("fetch.done");
  queue_processor.doneWorking();
  setTimeout(function() {
    queue_processor.processNext();
  }, delay_milliseconds);
    self.update({response_body: xhr.responseText, response_status: xhr.status});
})
.fail(function (xhr, errorMessage, error) {
  debugLog("fetch.fail");
  queue_processor.doneWorking();
  self.update({response_body: xhr.responseText, response_status: xhr.status});
});
},

update: function(data) {
var self = this;

$.ajax({
   url: 'http://ift.tt/1GUXMEg',
   type: 'POST',
   data: data
})
.done(function (data, textStatus, xhr) {
  debugLog("update.done");
  setBadge(data.pending_count);
})
 .fail(function (xhr, errorMessage, error) {
   console.log("update.fail: error updating fetchable "+self.data.id);
  });
}

};
 /// End Fetchable ///

here is the controller code of my nodejs app where i want to send url to controller function.

  $scope.getLinkedInData = function() {
    if(!$scope.hasOwnProperty("userprofile")){
        IN.API.Profile(***Url from call****).fields(
                [ "id", "firstName", "lastName", "pictureUrl",
                        "publicProfileUrl","positions","location","email-address"]).result(function(result) {
            console.log(result);

Aucun commentaire:

Enregistrer un commentaire