0
    var post = function() {
      angular.element('body').append('<form name="name" action="http://webservice.com">')
      angular.element('form[name="myForm"]').append(function(){
        var toAppend = '';
        angular.forEach([paramkey: paramValue],function(param,key){
          toAppend += '<input type="hidden" id="' + key + '" name="' + key + '" value="' + param + '">';
        });
        return toAppend;
      }).submit();

    };

I see this being used by fellow developers, and I was wondering why add all these when a $http({method: 'POST'}) will do the dirty work.

the result of this is that it downloads a passbook file.

I tried to replicate this call with $.ajax, and the file is not retrieved, is there a special header that i am missing?

user2167582
  • 5,103
  • 10
  • 50
  • 95
  • It's possible their webservice expects actual form data and not just POSTed json. – aet May 02 '14 at 22:06
  • there's no difference as far as http can tell right? if user were to change to form-encoded. – user2167582 May 03 '14 at 03:58
  • 1
    They are different. And processed differently by the backend, it does matter. – aet May 03 '14 at 04:39
  • ok, do you have a link to share that explain these differences? – user2167582 May 05 '14 at 15:44
  • When you post a form the data ends up in the body of the request in name/value format, see here: http://stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or-multipart-form-data When you post json, the data is still in the body of the request, but it is in json format, and not in name/value format, so the backend has to know (or determine via headers) what to expect. And likely there are many backends written before json became popular, so they may only support traditional form data. – aet May 05 '14 at 16:37
  • actually in network this is appended on to become params... not sure why – user2167582 May 06 '14 at 19:56

0 Answers0