r/angularjs • • Aug 28 '15

Why, AngularJS?

http://victorblog.com/2012/12/20/make-angularjs-http-service-behave-like-jquery-ajax/

This is a huge deal breaker for me. Are the devs addressing this or is it something they don't plan on supporting?

0 Upvotes

15 comments sorted by

View all comments

2

u/schizoduckie Aug 28 '15 edited Aug 28 '15

This article is severely outdated and the wrong way to post forms like this. You want to use angular.identity (which is basically a 'passthrough' transformer) for this and a FormData object:

var fd = new FormData();
fd.append('addlinktext', magnet);
fd.append('addlink', 'Add');

return $http.post(this.getUrl('addmagnet'), fd, {
    transformRequest: angular.identity,
    headers: {
        'Content-Type': undefined
    }
});

You can even upload files like this with zero effort, example here

-2

u/cj5 Aug 28 '15 edited Aug 28 '15

Sorry, but this doesn't work. I didn't think this would be put on the framework coder to handle transforms, and really breaks the flow of things. Wish I knew this before diving into angularjs >=/

1

u/schizoduckie Aug 28 '15

I have no idea what you mean. this should create a form with a regular formdata content-type. What kind of error are you seeing? because 'this doesn't work' is really not very useful

1

u/cj5 Aug 29 '15

I don't know, I've reverted my code before commit. I need to dive deeper into this when I have the time.