$http() vs $.ajax() different response

49 views
Skip to first unread message

korneliusz wilgocki

unread,
Oct 1, 2014, 8:58:33 AM10/1/14
to ang...@googlegroups.com
Hi

I have code in JQuery

$.ajax({
    method: 'DELETE',
    url: some_url,
    data: data
});

and in angular

var $query = $http({
   method: 'DELETE
   url: some_url,
   data: data
});


The response of this two request are different.
In first method when is an error i get error message return from backend like "You cant delete this element"  but in the second method I get all html error 500 page with html/body/js/css tags etc etc.  

Why ?

Sander Elias

unread,
Oct 2, 2014, 1:20:06 AM10/2/14
to ang...@googlegroups.com
Hi Korneliusz,

Did you examine the requests in the developers tools?
jQuery ajax does some not so standard things. Probably
a difference in headers.

Regards
Sander

Anton Trapp

unread,
Oct 2, 2014, 1:29:14 AM10/2/14
to ang...@googlegroups.com
Hi!

Check the request (headers like 'XMLHttpRequest' and check the log on the backend). I had some troubles that my Rails backend (especially the auth. system) did not notice the Ajax calls until I set

angularApp.config(['$httpProvider', ($httpProvider) ->
    $httpProvider
.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'

in Angular. If you can post what headers are going in and the server log we can make better guesses.

Regards,
Anton

korneliusz wilgocki

unread,
Oct 2, 2014, 3:41:16 AM10/2/14
to ang...@googlegroups.com
Anton great! Angular $http did not send this header. I set config and now it is working.

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Anton Trapp

unread,
Oct 3, 2014, 4:43:22 AM10/3/14
to ang...@googlegroups.com
Still a newbie on Angular, so I am glad that I can help and give something back to this community :)
Reply all
Reply to author
Forward
0 new messages