将Jsp响应转换为JSON

时间:2016-09-08 13:27:24

标签: javascript jquery angularjs ajax jsp

我有一个问题,因为我试图从angularjs中的jsp检索数据。这可行吗?如果没有..在角度js控制器中获取检索数据的其他方法是什么。任何人都可以帮我解决问题。我的守则如下......

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular-sanitize.min.js"></script>
<script>
    angular.module("myApp", []).controller('testController',['$scope', '$http', '$log', function($scope, $http, $log)
     {
                var stateNameHindi = "";
                var stateLandingPageUrl = "";
        $scope.ScopeObject = {
              states : [

             { name: "राज्य चुनें", Ename: "select", district: [{Hnname: 'जिला चुनें', DEname: "Select" }] },
             { name: "राजस्थान ", Ename: "Rajasthan", district: [{  Hnname: 'जयपुर' , DEname: "jaipur"}] },
             { name: "छत्तीस गढ़ ", Ename: "Chattisgarh", district: [{  Hnname: 'बिलास पुर', DEname: "Bilaspur"}, {  Hnname: 'रायपुर', DEname: "raipur"}] },
             { name: "गुजरात ",  Ename: "Gujrat", district: [ {  Hnname: 'अहमदाबाद', DEname: "Ahmdabad"}, {  Hnname: 'सूरत', DEname: "surat"}, {  Hnname: 'वड़ोदरा', DEname: "vadodra"} ] }

             ],

            } ;

        $scope.selectAction = function(EngStateName, EngCityName ) {
            var state = EngStateName.Ename;
            var city = EngCityName.DEname;

            $scope.CityData = $http.get('/xyz/CityNews.jsp', 
            {
                params:{state: state, city: city}})
            .then(function(response)
                    {
                     if (response.status == 200){
                alert("mayank");
                        $scope.CityData = JSON.parse(response);
                        alert("sing" + $scope.CityData);

                        $log.info(response);}
                    }, function myError(response) {
                        $scope.CityData  = response.statusText;
         });
        };    

       $scope.StateSelect = function(EngStateName) {
            var state = EngStateName.Ename;

            $scope.StateData = $http.get('/xyz/CityNews.jsp', 
            {
                params:{state: state}})
            .then(function(response)
                    {
                     if (response.status == 200){
                alert("mayank");
                        $scope.StateData =  JSON.stringify(response);
                        var data = JSON.parse($scope.CityData)
                        alert("sing" + data);
                        $log.info(response);}
                    }, function myError(response) {
                        $scope.CityData  = response.statusText;
         });
        };   

     }]);



 </script>



 <div ng-app="myApp">
<div ng-controller="testController">
        <select name="state"  ng-options="c.name for c in ScopeObject.states track by c.Ename" ng-model="ScopeObject.SelectedData" ng-change="StateSelect(ScopeObject.SelectedData)">
        <option value=''>राज्य चुनें</option>

        </select>
       <select district="cityname"  ng-options="d.Hnname for d in ScopeObject.SelectedData.district track by d.DEname" ng-model="ScopeObject.cityname" ng-change="selectAction(ScopeObject.SelectedData, ScopeObject.cityname )">
        <option value=''>जिला चुनें</option>
       </select>
        <p>  {{CityData}}   </p>
        <p>  {{StateData}}  </p> 
    </div>


 </div>

0 个答案:

没有答案