如何angularjs阿贾克斯成功后更改UI视图视图、angularjs、阿贾克斯、UI

2023-09-13 04:18:30 作者:什么不缺就是缺心眼

现在我想火寻找一个AJAX。之后我的$ HTTP(可能是$国土资源只是AJAX)的成功,我需要更新index.page用户界面视图显示结果。这里是我的code:

angular.module('ecom').config(['$stateProvider','$urlRouterProvider',function($stateProvider,$urlRouterProvider){    //任何无与伦比的网址,发送到/仪表板    $ urlRouterProvider.otherwise(/仪表板);    $ stateProvider     .STATE(家,             {            网址:'/家,            templateUrl:提交的/ home / home.html做为             })      .STATE('费用',              {            网址:'/费',            templateUrl:提交/支出/支出-list.html',            控制器:'SubmitterExpensesCtrl              })        .STATE('收据',              {            网址:'/收据,            templateUrl:提交/收据/ receipts.html              })        .STATE(设置,             {            网址:/设置            templateUrl:设置/ settings.html',            控制器:'SettingCtrl             })        .STATE('注销',              {            网址:'/注销,            templateUrl:'注销/ logout.html',            控制器:'LogoutCtrl              })        .STATE(信息搜索结果',                {            网址:'/信息搜索结果',            templateUrl:ExpenseResult / searchresult.html',            控制器:'resultCtrl                })}]);这是index.page:< NAV><搜索和GT;< /搜索>< / NAV> //当点击搜索,就会触发一个Ajax调用,我将结果显示在searchresult.html< D​​IV CLASS =身体容器>        < D​​IV CLASS =COL-MD-1>< / DIV>        < D​​IV CLASS =集装箱APP-包装COL-MD-12的UI视图>< / DIV> //主要内容将显示在这里。        < D​​IV CLASS =COL-MD-1>< / DIV>    < / DIV><页脚和GT;< /页脚>

我如何更改网址/结果,并在索引页显示searchresult.html?我可以尝试$ location.path('/信息搜索结果')在阿贾克斯seccuee方法?

解决方案 10 个非常有用的AngularJS 框架

注入$状态到控制器中,并调用$ state.go(Statename的),一旦$ HTTP / $资源调用返回的承诺。

所以你的情况,类似...

  $ http.post(/ AJAX)。然后(功能(数据,状态,头,配置){    $ state.go(信息搜索结果);}) 

Now I am trying to fire a ajax for search. after I $http( may be $resourse just ajax) success, I need to update the ui-view in index.page to show the result. Here is my code:

angular.module('ecom').config(['$stateProvider','$urlRouterProvider',function($stateProvider,$urlRouterProvider){
    //for any unmatched url,send to /dashboard
    $urlRouterProvider.otherwise("/dashboard");
    $stateProvider
     .state('home',
             {
            url:'/home',
            templateUrl:'submitter/home/home.html'
             }) 
      .state('expenses',
              {
            url:'/expenses',
            templateUrl:'submitter/expenses/expense-list.html',
            controller:'SubmitterExpensesCtrl'
              })
        .state('receipts',
              {
            url:'/receipts',
            templateUrl:'submitter/receipts/receipts.html'
              })
        .state('settings',
             {
            url:'/settings',
            templateUrl:'settings/settings.html',
            controller:'SettingCtrl'
             })
        .state('logout',
              {
            url:'/logout',
            templateUrl:'logout/logout.html',
            controller:'LogoutCtrl'
              })
        .state('searchResult',
                {
            url:'/searchresult',
            templateUrl:'ExpenseResult/searchresult.html',
            controller:'resultCtrl'     
                })
}]);
This is index.page :
<nav><search></search></nav> // When click search, it will fire a ajax call, I will display the result in searchresult.html
<div class="body-container">
        <div class="col-md-1"></div>
        <div class="container app-wrapper col-md-12" ui-view></div> //the main content will display here.
        <div class="col-md-1"></div>
    </div>
<footer></footer>

How can I change the url to /result and display the searchresult.html in of index page? Can I try $location.path('/searchresult') in ajax seccuee method?;

解决方案

Inject $state into your controller and call $state.go(statename) once the $http/$resource call has returned the promise.

So in your case, something like...

$http.post("/ajax")
.then(function(data, status, headers, config) {
    $state.go("searchResult");
})