0

Can I copy this code in my AngularJS APP. I'm new in AngularJS and I want to know. If I can copy this code done in javascript in my AngularJS APP

function callWS(url, type, dataType, data) { var resultado = ''; $.ajax({ url: url, type: type, dataType: dataType, contentType: "application/json; charset=utf-8", data: data, async: false, success: function(data) { resultado = data; }, error: function(e, msg) { console.log(msg + ' en ws ' + url); } }); return resultado; } 
3

3 Answers 3

1

Yes, you can use the same code with the help of $http in angular JS:

See below code:

var myAngApp = angular.module('AngularApp', []); myAngApp.controller('customController', function ($scope, $http) { $http({ url: url, type: type, dataType: dataType, contentType: "application/json; charset=utf-8", data: data, async: false, }).success(function (data, status, headers, config) { $scope.customers = data.d.results; }).error(function (data, status, headers, config) { }); }); 

Hope this will help you..!!

    0

    Yes you can use the code of core JavaScript in AngularJS but some different rules and code style. Here ajax code you are going to copy but i suggest you '$http' service of AnuglarJS. For More information here:https://docs.angularjs.org/api/ng/service/$http

      0

      If you want to use Angular, you don't need to use jquery functions. Use Restangular to handle Rest API Restful Resources. It's powerfull and easy: https://github.com/mgonto/restangular

        Start asking to get answers

        Find the answer to your question by asking.

        Ask question

        Explore related questions

        See similar questions with these tags.