title: How to use the return callback object from express in angularJS
body: <p>All:</p>
  
  <blockquote>
    <p><strong>[UPDATE]</strong> I figure it out, it turns out that:</p>
  </blockquote>
  
  <pre><code>        $http({
              url: "http://localhost:3000/users",
              method: "JSONP",
              params: {
                  callback:"JSON_CALLBACK", // need to be this name
  
                  q: $scope.qs
              }
          })
          .success(function( data ){   
              console.log("return data length:",data.length);
              if(data.length&gt;0){
                  $scope.cdata = data;
              }
          })
  </code></pre>
  
  <p>==========================================================
  I am new to ExpressJS and AngularJS, right now, I m trying to use Express to build a REST JSONP service to provide data.</p>
  
  <p>And when I try Angular in the frontend like:</p>
  
  <pre><code>            $scope.qs = 0;
  
              $http({
                  url: "http://localhost:3000/users",
                  method: "JSONP",
                  params: {
                      callback:"dataservice",
                      q: $scope.qs
                  }
              })
              .success(function(err, data){  
                  console.log("return data length:",data.length);
                  if(data.length&gt;0){
                      $scope.cdata = data;
                  }
              })
              .error(function(data, err){
                  console.log(data, err);
              });
          };
  </code></pre>
  
  <p>Annd on server side I use:</p>
  
  <pre><code>/* GET users listing. */
  router.get('/', function(req, res) {
  
      var jsonp = req.query.callback;
      var start = parseInt(req.query.q);
      var retdata = [];
  
  
      if( !isNaN(start) ){
          retdata = cdata.slice(start);
      }
      if(jsonp){
          console.log("I return as JSONP");
          res.jsonp( retdata );
      }else {
          console.log("I return as JSON");
          res.json( retdata );
      }
  });
  </code></pre>
  
  <p>From chrome console, I can see the return JSONP response is like:</p>
  
  <pre><code>/**/ typeof dataservice === 'function' &amp;&amp; dataservice([{"Name":"Island Trading","City":"Cowes","Country":"UK"},{"Name":"Königlich Essen","City":"Brandenburg","Country":"Germany"},{"Name":"Laughing Bacchus Wine Cellars","City":"Vancouver","Country":"Canada"},{"Name":"Magazzini Alimentari Riuniti","City":"Bergamo","Country":"Italy"},{"Name":"North/South","City":"London","Country":"UK"},{"Name":"Paris spécialités","City":"Paris","Country":"France"},{"Name":"Rattlesnake Canyon Grocery","City":"Albuquerque","Country":"USA"},{"Name":"Simons bistro","City":"København","Country":"Denmark"},{"Name":"The Big Cheese","City":"Portland","Country":"USA"},{"Name":"Vaffeljernet","City":"Århus","Country":"Denmark"},{"Name":"Wolski Zajazd","City":"Warszawa","Country":"Poland"}]);
  </code></pre>
  
  <p>But Angular can not use it in .successs, but trigger the .error handler.</p>
  
  <p>I wonder if anyone can help me with this? How to use the return response</p>
  
  <p>Thanks</p>