Я использую ZF2 и AngularJS для создания приложения для викторины. Когда я запускаю код, ошибки не возникает, и результата нет.
(function(angular) {
function MainController($scope,$http) {
$scope.question = function(id)
{
var site = "http://localhost/zf/public/interviewer";
var page = "/jsonquestion/"+id;
alert(site + page);
var reqQuestion = $http.get(site + page);
reqQuestion.success(function(data, status, headers, config) {$scope.question.questions = data;});
reqQuestion.error(function(data, status, headers, config){alert("AJAX failed!");});
alert(data);
}
};
angular.module("app", []).controller("MainController", ["$scope", MainController]);
}) (угловой);
Моя Зенд часть
public function jsonquestionAction()
{
$id = (int) $this->params()->fromRoute('id', 0);
$questions = $this->getQuestionsTable()->getQuestions($id);
$result = json_encode($questions);
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
fwrite($myfile, $result);
fclose($myfile);
echo $result;
return $result;
}
Когда я звоню http://localhost/zf/public/interviewer/jsonquestion/1
из браузера его работы и возвращения JSon
Thakyou. Работает –