Many times we need to use ajax to submit post data. Angularjs is similar to jq and also has encapsulated posts.
But jQuery’s post is obviously simpler and more user-friendly than angularjs’s.
AngularJS:
jQuery:
Looks like there’s no difference, right? However, the data submitted using $http of angularjs cannot be obtained through $_REQUEST/$_POST on the PHP server. Instead, you need to use:
to get it. What's the reason?
This is because the two posts handle headers differently... jQuery will serialize myData as a JSON object, for example:
And Angular doesn’t.
What’s the solution?
1. Introduce jquery, provided that the target users don’t mind loading an extra tens of K scripts. (Not recommended)
2. Get parameters on the server side (PHP) through $params = json_decode(file_get_contents('php://input'),true);. Small projects can do this, but large projects need to be changed one by one. (Not recommended)
3. Modify the default processing of Angular's $httpProvider: http://victorblog.com/2012/12/20/make-angularjs-http-service-behave-like-jquery-ajax/ (In order to facilitate future management, this is the best way)
Do you guys have a better understanding of the difference between $http.post and jQuery.post in AngularJS? I hope you will gain something from reading this article.