English 中文(简体)
Asp.NET MVC Ajax-Post a FORM and Ajax-Get
原标题:Asp.NET MVC Ajax-Post a FORM and Ajax-Get
  • 时间:2009-09-02 13:45:11
  •  标签:

我 st,谁能帮助我? 在我的Logon.aspx 表格内的I velogin控制(Username, Password, RememberMe):

<form id="loginform" method="post" action="/Account/LogOn/">

下面,我把一个隐蔽的DIV带上一份《禁用清单》和一份确认书,上面有一张浮雕:

$.ajaxSetup({ cache: false });
$.ajax({
    type: "GET",
    url: "/Account/SetCompanyAndContinue",
    data: "{  id  :  1 }",
    contentType: "application/json; charset=utf-8",
    dataType: "json"
});

首先,用户记录。 在 j,我通过日本宇宙航空研究开发机构将 log证书张贴在:

var loginCred = new Object();
loginCred.Username = $( #userName ).val();
loginCred.Password = $( #password ).val();
loginCred.RememberMe = $( #rememberMe ).checked;

var myJsonObject = JSON.stringify(loginCred);

$.ajaxSetup({ cache: false });
$.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: "/Account/LogOnAjax/",
    data: myJsonObject,
    dataType: "json",
    success: function(data) {
        PostCredentialsSuccess(data);
    }
});

该《行动计划》是完美的。 主计长行动上的突破点受到夸张的打击,并退回了一名JSON的数据标。 我将这名JSON数据列入《削减措施》清单。 然后向用户提交该选择清单。 然后,当用户点击确认书丁顿时,又发出第二次美国宇宙航空研究开发机构呼吁:

$.ajaxSetup({ cache: false });
$.ajax({
    type: "GET",
    url: "/Account/SetCompanyAndContinue",
    data: "{  id  :  1 }",
    contentType: "application/json; charset=utf-8",
    dataType: "json"
});

我预计,名为“SetCompanyAndContinue”的主计长行动会受到打击:

    [AcceptVerbs(HttpVerbs.Get)]
    public ActionResult SetCompanyAndContinue(string id)
    {
        SessionAdapter.CustomerID = Convert.ToInt32(id);
        return null;
    }

但是,这种情况正在发生,而缺席的主计长行动却第一次受到打击:

    public ActionResult LogOn()
    {
        return View();
    }

BUT(!) 我第二次点击(同一次)证实主计长行动最终点击[SetCompanyAndContinue]。

有些人能告诉我我我我我我我什么是错的? 很多人预先表示感谢。

最佳回答

我代表我犯以下错误:

  • i ve added a cookie to the response-stream which made the webbrower behave unpredictable.
  • i ve forgot to mark this one as answered
问题回答

您需要将数据财产作为单字母物体,而不是作为示意图。

    $.ajax({ type: "GET",
    url: "/Account/SetCompanyAndContinue",
    data: ({id : 1}),
    contentType: "application/json; charset=utf-8", 
    dataType: "json" });

i 建议使用火力来审视吉大港山区的实际要求,而这种请求确实来自 j,因此,像这种微小的错误非常迅速。

h)

尝试使用链路提交,而不是正常提交纽州,在点击、ja和形式之间可能有一些冲突。

I didn t know whether I got the correct information. But as per your description any click on the "submit" button will try to do the "Post" method and not the "Get" method. The "Get" call is done only when you visit the page at first or refresh the url. Use the link button to do the "Get" action.

因此,在你抽样中,用“Post”方法对“Account/logOnAjax/”这一行动进行了抽样调查。

比较不同的GET请求,请您使用FiddlerCharles

婚姻是正确的

umb的一般规则(至少对我来说是可行的):如果你的行动像你所期望的那样受到打击,那么,如果你走过路,或者如果你回到违约的道路上,那么,用该哨所发送的形式数据就是预期的。 我正在使用(这笔)美元,作为JQuery公司的一笔钱,而我的一个隐蔽的形式田是空的。 这一行动在任何路线上都是一帆风顺的(我让它陷入本案的违约状态),从未见过这个职位。





相关问题
热门标签