如何在视图中使用ajax [英] How to use ajax in view

查看:99
本文介绍了如何在视图中使用ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

点击视图中的保存按钮我写了以下代码。但它没有重定向到url。如果我不提及The Url,那么它也会自动重定向到相应的控制器HttpPost方法..

 $( document )。ready( function (){alert(   yy); 
$( #save)。click( function (){
var json = {'USER_NAME':' + escape (USER_NAME.val())+ ' ,'MOBILE_NO':' + 转义(MOBILE_NO.val())+ '};
警报(JSON);
alert( RRR);
// var ajaxPage =〜/ Book / Employee / {0};
alert(ajaxPage);

$ .ajax(
{
type: POST
url:ajaxPage,
data:json,
contentType: application / json; charset = utf-8
dataType: json
异步: false
成功:功能(数据){
if (data.Message == 数据删除Succeffully){
showMessage(data.Message);
$(' #table')。dataTable()。fnAddData();
filltable();

}
else {
showMessage(data.Message);
}
},
错误: function (msg){alert( 失败: + msg); }
});
})
});
< / script>



Plz帮助如何在视图上使用ajax ???

解决方案

< blockquote>( document )。ready( function (){alert( yy);


#save)。click( function (){
var json = {'USER_NAME':' + < span class =code-sdkkeyword> escape (USER_NAME.val())+ ',' MOBILE_NO':' + escape (MOBILE_NO.val())+ '};
alert(json);
alert( RRR< /跨度>);
// var ajaxPage =〜/ Book / Employee / {0};
alert(ajaxPage);


.ajax(
{
type: POST
url:ajaxPage,
data:json,
contentType: application / json; charset = utf-8
dataType: json
async: false
成功:功能(数据){
if (data.Message == 数据删除Succeffully){
showMessage(data.Message);


On clicking on Save button in view i have following code written.But It doesnt redirect to the url.If i dont mention The Url then also it automatically redirect to the corresponding controller HttpPost method..

$(document).ready(function () { alert("yy");
   $("#save").click(function () {
       var json = "{'USER_NAME':'" + escape(USER_NAME.val()) + "','MOBILE_NO':'" + escape(MOBILE_NO.val()) + "'}";
       alert(json);
       alert("RRR");
      // var ajaxPage = "~/Book/Employee/{0}";
       alert(ajaxPage);
        
       $.ajax(
       {
           type: "POST",
           url: ajaxPage,
           data: json,
           contentType: "application/json;charset=utf-8",
           dataType: "json",
           async: false,
           success: function (data) {
               if (data.Message == "Data Deleted Succeffully") {
                   showMessage(data.Message);
                   $('#table').dataTable().fnAddData();
                   filltable();

               }
               else {
                   showMessage(data.Message);
               }
           },
           error: function (msg) { alert("failed: " + msg); }
       });
   })
});
</script>


Plz help how to use ajax on view???

解决方案

(document).ready(function () { alert("yy");


("#save").click(function () { var json = "{'USER_NAME':'" + escape(USER_NAME.val()) + "','MOBILE_NO':'" + escape(MOBILE_NO.val()) + "'}"; alert(json); alert("RRR"); // var ajaxPage = "~/Book/Employee/{0}"; alert(ajaxPage);


.ajax( { type: "POST", url: ajaxPage, data: json, contentType: "application/json;charset=utf-8", dataType: "json", async: false, success: function (data) { if (data.Message == "Data Deleted Succeffully") { showMessage(data.Message);


这篇关于如何在视图中使用ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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