使用Java BackEnd

时间:2017-04-28 09:11:18

标签: angularjs ajax

事情就像标题中所说的那样。

(function(){
    var app = angular.module('sbi', [ ]);
    app.controller('PanelController', function (){
        this.tab = 1;

        this.selectTab = function (setTab){
            this.tab = setTab;
        };
        this.isSelected = function(checkTab) {
            return this.tab === checkTab;
        };
      });


app.controller('MyCtrl', function($scope, $compile) {
      'use strict';

      $scope.data = { "name": ""};

        $scope.reset = function() {
          $scope.data.name = "";
          $scope.data.codeSub = "";
          $scope.data.cognSub = "";
          $scope.data.codfis = "";
          $scope.data.drpdownvalue = "";
          $scope.form.$setPristine();
        }
    });
app.controller('DdController', function($scope, $compile) {
    'use strict';

    var loadUrl = contextName+"/subinstaller/inserimento/dettaglio.do?methodName=doListenerStato";
    $.ajax({
        async: false,
        url : loadUrl,
        type: "GET",
        data: data, 
        dataType: 'json',
        cache: false,
        complete: function(){
            _show_(false,'waitPanel');
        },
        success : function (data, stato) {
            $('#service').empty()
            for(var i = 0; i < data.length; i++) {
                $("#service").append($('<option value="'+data[i].code+'">'+data[i].descr+'</option>'));                 
            }
            $('#service').trigger("chosen:updated");
        },
        error : function (richiesta, stato, errori) {
            _show_(false,'waitPanel');
            alert("error caricaServices");
        }
    });
    });


})();
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script><!DOCTYPE html>
<html ng-app="sbi">
<head>
    <link href="utils/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <style>
        table, td  { border-width: 2px; border-collapse: collapse; padding: 15px; color: #000000; text-align: center; }
        table.pos_fixed1 { position:relative; top:30px; left:10px; }
    </style>
</head>
<body>


<form name="form">
            <div data-ng-controller="MyCtrl">
            <table summary="" width="10%" class="pos_fixed1" align="center">
            <tr><td>Code Subinstaller<br><input type="text" ng-model="data.codeSub" /></td>
            <td>Stato<br>
            <select ng-model="data.drpdownvalue">
            <option value=""> -- Seleziona -- </option>
        </select> </td><td></td></tr>
            <tr><td>Nome Sub Installer<input type="text" ng-model="data.name" /></td>
            <td>Cognome Sub Installer<input type="text" ng-model="data.cognSub" /></td>
            <td>Codice Fiscale<input type="text" ng-model="data.codfis" /></td></tr>
        </table><br><br>
        </form>
        <section>
            <div class="text-center">
            <form name="form" id="form" novalidate>
                  <div>
            <button class="btn-xs" data-ng-click="">Cerca</button>
            <button class="btn-xs" ng-click="reset()">Pulisci</button>
            </div>
            </div>
            </form>
            </div>
        </section>


 <section ng-controller="PanelController as panel">
 <ul class="nav nav-pills" >
<li ng-class="{ active:panel.isSelected(1) }"> <a href ng-click="panel.selectTab(1)">Risultati</a></li>
<li ng-class="{ active:panel.isSelected(2) }"> <a href ng-click="panel.selectTab(2)">Dettaglio</a></li>
 </ul>

 <div class="panel" ng-show="panel.isSelected(1)">
 <h4>Risultati</h4>
 <p> :))) </p>
 </div>
  <div class="panel" ng-show="panel.isSelected(2)">
 <h4>Dettaglio</h4>
 <p> Not skilled enough yet</p>
 </div>




</section>



<script type="text/javascript" src="utils/angular.min.js"></script>
<script type="text/javascript" src="controllers/sbi_inserimento_controller1.js"></script>

</body>
</html>

函数“DoListenerStato”有它的查询,它可以工作(在Java中试过) 但是组合框没有被填充。 我是否正确使用过ajax?如果是这样,我该怎么办? 如果可能的话,我宁愿继续使用ajax进行这项工作。

1 个答案:

答案 0 :(得分:1)

您可以尝试$http.get而不是$.ajax

<{1>}文件中的

Controller.js

由于您$scope.data = {}; $http.get(loadUrl).then(function (response){ $scope.data = response.data; //success callback }, function (response) { //error callback }); 已经有data.****,因此应解决此问题。