Jquery Ajax调用不是触发器 [英] Jquery Ajax call not trigger

查看:70
本文介绍了Jquery Ajax调用不是触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中编写了一个jquery ajax调用但在我看来并不触发

我无法找到解决此问题的方法。



Js代码: -



var producer =test;

var json = {EmailId:producer};

$ .ajax({

type:POST,

url:/ account / ForgotPassword /,

数据:json,

contentType:application / json; charset = utf-8,

dataType: json,

成功:功能(数据){

alert(okay);

},



错误:功能(数据){

提醒(不行);

}

} );



控制器: -



I am writing one jquery ajax call in my application but it was not trigger in my view
I could not able to find the solution for this issue.

Js Code:-

var producer = "test";
var json = { "EmailId": producer};
$.ajax({
type: "POST",
url: "/Account/ForgotPassword/",
data: json,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert("okay");
},

error: function (data) {
alert("not okay");
}
});

Controller:-

[HttpPost]
       [AllowAnonymous]
      [ValidateAntiForgeryToken]
       public ActionResult ForgotPassword(string EmailId)
       {
         return view();
       }

推荐答案

.ajax({

类型:POST,
url:/ Account / ForgotPassword /,

数据:json,

contentType:application / json; charset = utf-8,

dataType:json,

成功:函数(数据){

alert(okay);

},



错误:功能(数据){

alert(不行);

}

});



控制器: -



.ajax({
type: "POST",
url: "/Account/ForgotPassword/",
data: json,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert("okay");
},

error: function (data) {
alert("not okay");
}
});

Controller:-

[HttpPost]
       [AllowAnonymous]
      [ValidateAntiForgeryToken]
       public ActionResult ForgotPassword(string EmailId)
       {
         return view();
       }


要在ajax调用中验证防伪标记,您需要稍作更改。



以下是我的索引页面。

For validating anti forgery token with in ajax call, you need to do a slight change.

Below is my Index page.
<form id="__AjaxAntiForgeryForm" action="#" method="post">

     @Html.AntiForgeryToken()
    <button onclick="test()">
        ClickMe
    </button>
   
</form>





现在保留您的Javascript代码略微修改如下。





Now keeping your Javascript code with slight modification as below.

<script>
       function test() {

           AddAntiForgeryToken = function (data) {
               data.__RequestVerificationToken =


' #__ AjaxAntiForgeryForm输入[名称= __ RequestVerificationToken]')VAL();
返回数据;
};
var producer = test;
var json = AddAntiForgeryToken({ EmailId :producer});
('#__AjaxAntiForgeryForm input[name=__RequestVerificationToken]').val(); return data; }; var producer = "test"; var json = AddAntiForgeryToken( { "EmailId": producer });


这篇关于Jquery Ajax调用不是触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆