我在 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);
}
}
}