0

Hi I have a project in Flash, which calls the AMFPHP for server side integration. Now I want the same connection with Angular JS or any Javascript. So is it possible to make this happen? Actually I don't want to change the Server, because of some issue. I can change the Client Side. So please let me know, if its possible. I tried http://www.bennadel.com/blog/2612-using-the-http-service-in-angularjs-to-make-ajax-requests.htm URL but no success.

VarunJi
  • 685
  • 2
  • 14
  • 31
  • 1
    I wouldn't look at this from an angular perspective since ultimately the problem is just the AMF encoded request/response and how to read that in JS. If there's a way to parse and serialize from JS to AMF then you can plug that into the $http config instead of letting it do it's regular JSON parse and stringify. Something like this should work https://github.com/infomaniac-amf/js – shaunhusain Oct 17 '15 at 16:15

2 Answers2

0

I can provide you with a jQuery ajax call. It's almost as simple as this:

<script language="javascript">
    function call(){
        /**
         * notes:
         * - parameters here could be left empty, they are just here to make the code easier to adapt
         * - $.post method here is used because amfPHP JSON plugin expects data as POST. So can't use more obvious getJSON
         * - if you always use the same parameters, you can do without json2.js, by setting for example
         * callData = '{"serviceName":"PizzaService", "methodName":"getPizza","parameters":[]}'
         */

        var callData = JSON.stringify({"serviceName": "YourController", "methodName": "getSomething", "parameters": []});
        $.post("../amfphp/?contentType=application/json", callData, onSuccess);

    }

    function onSuccess(data){
        alert("pizza : " + data);
    }
</script>

The important key notes here are:

?contentType=application/json

At the URL Query. That will tell AMF that you want it to return a JSON format instead of a AMF Request.

Now, since you're going with AngularJS, one more thing you should be aware is the fact that angular already sets ajax communication with applicatio/json. So I can't really tell you how amfPHP will handle this. Personally, I believe that if a jQuery call querying an application/json works successfully, your Ajax call from AngularJS will work automatically. If it doesn't, you can try to debug amfPHP and try to see if $_POST or $_REQUEST is being feeded.

You may find some additional information about angularJS and PHP here.

Community
  • 1
  • 1
Marco Aurélio Deleu
  • 4,279
  • 4
  • 35
  • 63
-1

You should be able to use the library I linked above and

$httpProvider.defaults.transformRequest
$httpProvider.defaults.transformResponse

you can configure the $http provider in an angular config block. Something like

angular.module('myApp',[]).config(function($httpProvider){
  $httpProvider.defaults.transformRequest = AMF.stringify;
  $httpProvider.defaults.transformResponse = AMF.parse;
});
shaunhusain
  • 19,630
  • 4
  • 38
  • 51