简体   繁体   English

使用angular js ajax调用调用php json服务文件

[英]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 我正在使用angular js,我需要ot调用一个以json格式返回数据的php服务文件,如果我将data(json)放在本地可以正常工作,则无法从angular js进行ajax请求

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. 我建议您使用内置的AngularJS $ http服务。 Official documentation, with examples: 官方文档,包括示例:

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

Remember to inject $http into your service or controller. 请记住将$ http注入您的服务或控制器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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