title: Using Angularjs how I can do ajax call?
body: <p>Here is a drop down menu. I am fetching the drop down values from the database using <code>AJAX</code> and <code>AngularJS</code>.</p>
  <p><strong>HTML code:</strong></p>
  <pre><code>&lt;body ng-app=&quot;myApp&quot;&gt;
  &lt;div ng-controller=&quot;MyController&quot; &gt;
    &lt;select ng-model=&quot;myForm.car&quot; ng-options=&quot;obj.id as obj.name for obj in myForm.options&quot;&gt;
                                  &lt;/select&gt;
   &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  <p><strong>4 js files included:</strong></p>
  <pre><code>&lt;script src=&quot;angular.js&quot;&gt;&lt;/script&gt;
  &lt;script src=&quot;controllers.js&quot;&gt;&lt;/script&gt;
  &lt;script src=&quot;jquery-min.js&quot;&gt;&lt;/script&gt;
  &lt;script src=&quot;ajaxload.js&quot;&gt;&lt;/script&gt;
  </code></pre>
  <p><strong>controller.js</strong> contains an angular function. This angular function will make an ajax call and it will call the PHP file. The PHP file will get the result from database. I have done the value fetching from database, but the values are not coming as a response.</p>
  <p><strong>controller.js code:</strong></p>
  <pre><code> angular.module(&quot;myApp&quot;, [])
              .controller(&quot;MyController&quot;, function($scope) {
               $scope.myForm = {};
               $scope.myForm.car  = &quot;nissan&quot;;
                              
                $.ajax({url: &quot;/getCars/&quot;}).success(function(data) 
                {
                  $scope.myForm.options = data;
                })
               });
  </code></pre>
  <p>In the PHP file I already fetched the details and stored it in an array. This array I am returning by using <code>json_encode</code> method.</p>
  <pre><code>function getCars()
          {       
            $cars = array
                (
                array(&quot;id&quot; =&gt; &quot;nissan&quot;, &quot;name&quot; =&gt; &quot;Nissan&quot;),
                array(&quot;id&quot; =&gt; &quot;toyota&quot;, &quot;name&quot;=&gt; &quot;Toyota&quot;),
                array(&quot;id&quot; =&gt; &quot;fiat&quot;  , &quot;name&quot;=&gt; &quot;Fiat&quot;),
                array(&quot;id&quot; =&gt; &quot;Land Rover&quot;  , &quot;name&quot;=&gt; &quot;Land Rover&quot;)
                );           
           print json_encode($cars);
           exit;
          }   
  </code></pre>