douzhuolong9886 2014-07-10 10:27
浏览 43

使用Angularjs我怎么能做ajax调用?

Here is a drop down.The drop down values I am fetching from database using ajax and angularjs

HTML code

<body ng-app="myApp">
<div ng-controller="MyController" >
  <select ng-model="myForm.car" ng-options="obj.id as obj.name for obj in myForm.options">
                                </select>
 </div>
</body>

4 js file included

<script src="angular.js"></script>
<script src="controllers.js"></script>
<script src="jquery-min.js"></script>
<script src="ajaxload.js"></script>

controller.js contain angular function this angular function will make an ajax call it will call the php file. php file will get the result from database. I have done the fetching values from database.But the values are not coming as a response

contoller.js

 angular.module("myApp", [])
            .controller("MyController", function($scope) {
             $scope.myForm = {};
             $scope.myForm.car  = "nissan";

              $.ajax({url: "/getCars/"}).success(function(data) 
              {
                $scope.myForm.options = data;
              })

             } );

php file I already fetch the details and stored it in an array.this array I am returning by json_encode method

function getCars()
        {       
          $cars = array
              (
              array("id" => "nissan", "name" => "Nissan"),
              array("id" => "toyota", "name"=> "Toyota"),
              array("id" => "fiat"  , "name"=> "Fiat"),
              array("id" => "Land Rover"  , "name"=> "Land Rover")
              );           
         print json_encode($cars);
         exit;

        }   
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥15 stable diffusion
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘