简体   繁体   中英

calling php json service file using angular js ajax call

Am working on angular js and i need ot call a php service file which returns data in json format,am unable to make an ajax reques from angular js well if i place the data(json)in local its working fine

var test = angular.module('TestService', []);

test.factory('TestService', function($http){

            return{

                  getTheTest:function(callback){


             $.ajax({
                    type: "GET",
                   // url: "https://angularjs.org/greet.php?callback=JSON_CALLBACK&name=Super%20Hero",
                    url: 'http://www.domain.com/alumni/wsQuestions.php?courseId=1&modeId=1',
                    contentType: "application/json",
                    dataType: "jsonp",
                    processData: true,
                    success: function (data, status, jqXHR) {
                    alert('Success :'+JSON.stringify(data));
                    console.log('Success :' + JSON.stringify(jqXHR) +"\n"+ "response: "+ JSON.stringify(data));
                    },
                    error: function (xhr) {
                  alert('Error :' +xhr.responseText);
                    console.log('error'+ JSON.stringify(xhr));
                    }
                    });



             }


             }
});

I recommend that you use the built-in AngularJS $http service. Official documentation, with examples:

https://docs.angularjs.org/api/ngResource/service/ $http

Remember to inject $http into your service or controller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM