1

我在 angular 的工厂中使用 ajax 的 post 请求....除了 ajax 成功功能之外一切正常...你可以在成功功能中看到我必须转到另一个页面..(logout.html).. 但是 ajax 的成功功能在单击登录按钮两次后将我登录到第二页,我不知道是什么问题请帮助

我在 Angular 工厂中的 ajax 调用

demoapp.factory("authser", function ($location) {
    return {
        login: function (credantials) {
            if (credantials.username != "jot") {
                alert("its ");
            }
            else {
                $.ajax({
                    url: "/valued/newvalue",
                    type: 'POST',
                    data: { 'name': credantials.username, 'password': credantials.password },
                    dataType: "json",
                    success: function (data) {
                        console.log(data);
                        $location.path('/logout');

                    }
                });
            }
        },
        logout: function (data) {
console.log(data);

            $location.path('/hello');
        }
    }
})

我的控制器

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace angulardata.Controllers
{
    public class valuedController : Controller
    {
       // GET: /valued/
        [HttpPost]
        public ActionResult newvalue(string name, string password)
        {
            var res = new {Success="True",Message="Error MEssage" };
            return Json(res);
        }

    }
}
4

1 回答 1

1

而不是使用 $.ajax尝试使用$http角度服务来调用将触发角度摘要循环的服务器。

demoapp.factory("authser", function ($location,$http) {

//

$http({
    method: 'POST',
    url:  "/valued/newvalue",
    responseType: "json",
   data: { 'name': credantials.username, 'password': credantials.password }
}).success(function (data) {
   console.log(data);
   $location.path('/logout');
});
于 2014-02-19T06:09:39.907 回答