Transforming AngularJS Requests for PHP
05/22/2015 Sean Cole Comments 0
I picked up AngularJS about five or six months ago for a project at work. Early on I decided that I didn’t want to confuse the issue by having to learn a new language at the same time, so I decided to use PHP for my back-end. If you are at all familiar with AngularJS you may begin to see the problems I was about to encounter. At first, development was flawless, even enjoyable; However, when I started implementing my forms I began to notice that something was wrong. None of my form fields were being submitted to my PHP scripts!
After much digging I eventually came across a post that mentioned the
$httpProvider in conjunction with
transformRequest and I was able to narrow my focus until I eventually found this extremely useful blog post. Below, I have adapted Victor’s script to utilize John Papa’s Style Guide, which made it easier to apply some DRY principles to without cluttering the global scope.
I urge you to read Victor’s blog post about this as it goes into an in depth explanation and points out some important caveats about jQuery’s
$.param() function and PHP’s input streams.