Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在jquery post之后更新div显示,而无需在mvc3中重新加载页面_Javascript_Jquery_Ajax_Asp.net Mvc 3 - Fatal编程技术网

Javascript 在jquery post之后更新div显示,而无需在mvc3中重新加载页面

Javascript 在jquery post之后更新div显示,而无需在mvc3中重新加载页面,javascript,jquery,ajax,asp.net-mvc-3,Javascript,Jquery,Ajax,Asp.net Mvc 3,大家好,这里是MVC3新手!请看一下这些: 在我的查看页面中,我有: <div id = "AccounStatusDiv" class="display-field"> @Html.DisplayFor(m => m.AccountStatus) <input id="btnBool" type="button" class="btnGrid ActStatBtn" value="@(Model.AccountStatus ? "Deacti

大家好,这里是MVC3新手!请看一下这些:

在我的查看页面中,我有:

    <div id = "AccounStatusDiv" class="display-field">
     @Html.DisplayFor(m => m.AccountStatus)
     <input id="btnBool" type="button" class="btnGrid ActStatBtn" value="@(Model.AccountStatus ? "Deactivate" : "Activate")" onclick="ChangeStatus()"/>
    </div>
     <div id = "AccountStatusDiv" style="display:inline-block;">
       <img src="@Html.Custom().ResolveImage((bool)Model ? imgPositive : imgNegative)" alt="@Model" />
       <label> @ResourceManager.Localize(resource, display)</label>
      </div>
结果仅在我重新加载页面后显示。 我想在单击
btnBool
后立即显示更新的
img
标签
btnBool
元素,而无需重新加载整个页面。在这种情况下,最好的方法是什么? 请张贴您的代码建议,这将是一个伟大的帮助我!
提前谢谢

这是一个事件点击按钮,无需刷新页面

$("#btnBool").click(function(e){
e.preventDefault();
//to do your code, you can use `$.ajax` to request and get response from server
  $.ajax({
    url: '@Url.Action("SetAccountStatus", "User")',
    type:"GET",
    dataType: 'json',
    data: { UserName: "@(Model.UserName)",accountStatus: "@(Model.AccountStatus)" },
    async:'true',
    success:function (data) {
     alert(data);
     //success   to parsing json if you data type of your response is json
    }
   }); 
}

您可以使用web服务发送请求并从服务器获取响应,以及从服务器获取请求和响应。您可以在jquery中使用
$.ajax()
,这是一个事件点击按钮,无需刷新页面

$("#btnBool").click(function(e){
e.preventDefault();
//to do your code, you can use `$.ajax` to request and get response from server
  $.ajax({
    url: '@Url.Action("SetAccountStatus", "User")',
    type:"GET",
    dataType: 'json',
    data: { UserName: "@(Model.UserName)",accountStatus: "@(Model.AccountStatus)" },
    async:'true',
    success:function (data) {
     alert(data);
     //success   to parsing json if you data type of your response is json
    }
   }); 
}

您可以使用web服务从服务器发送请求和获取响应,以及从服务器请求和获取响应。您可以在jquery中使用
$.ajax()
您只使用
$.post()
向服务器发送数据(请求)。AJAX可以有两种:发送请求和接收相应的响应。在您的代码中,您没有接收回数据(或者,至少没有做出必要的安排,以便您能够接收到数据)

如果
UserController
SetAccountStatus
操作设置为返回一些数据(可能通过
return Json()
或类似方式),则可以修改
$.post()
调用以接收它,并让Javascript使用回调函数做出相应的反应

var data = {
    UserName: "@Model.UserName",
    accountStatus: "@Model.AccountStatus" 
};

var call = $.post(
    '@Url.Action("SetAccountStatus", "User")',
    data
);

// set the success callback here
call.success(function (m) {

    // the [m] variable contains the data returned by the server
    // during the resolution of your call

    // this will be called when your AJAX call succeeds,
    // and you can use this opportunity to update the HTML DOM with new data

});

您仅使用
$.post()
向服务器发送数据(请求)。AJAX可以有两种:发送请求和接收相应的响应。在您的代码中,您没有接收回数据(或者,至少没有做出必要的安排,以便您能够接收到数据)

如果
UserController
SetAccountStatus
操作设置为返回一些数据(可能通过
return Json()
或类似方式),则可以修改
$.post()
调用以接收它,并让Javascript使用回调函数做出相应的反应

var data = {
    UserName: "@Model.UserName",
    accountStatus: "@Model.AccountStatus" 
};

var call = $.post(
    '@Url.Action("SetAccountStatus", "User")',
    data
);

// set the success callback here
call.success(function (m) {

    // the [m] variable contains the data returned by the server
    // during the resolution of your call

    // this will be called when your AJAX call succeeds,
    // and you can use this opportunity to update the HTML DOM with new data

});

您可以看到我在演示中用
JSONP
url实现的这个演示是web服务,我用
$.ajax()
解析数据,您可以看到,如果单击按钮,数据将显示出来,这不是刷新或加载页面。此技术是客户端-服务器通信服务器中响应上的数据类型是什么?或者你可以在这里发布什么响应?请看我更新的问题,我已经在那里包含了
SetAccountStatus
操作。嘿,我想你可以参考这个问题,你可以看到这个演示我在演示中用
JSONP
url实现的是web服务,我正在用
$.ajax()解析数据
您可以看到,如果单击按钮,数据将显示出来,这不是刷新或加载页面。此技术是客户端-服务器通信服务器中响应上的数据类型是什么?或者你可以在这里发布什么是响应?请查看我的更新问题,我已经在那里包含了
SetAccountStatus
操作。嘿,我想你可以参考这个问题。你能给我ca.success函数的确切代码吗?请看我更新的帖子。我已经包括了
SetAccountStatus
操作。在您的操作中,您明确地告诉服务器执行重定向。如果希望客户端页面不重新加载,为什么要这样做?那么如何使此操作不重新加载?我的任务是“编辑”已经编码好的web应用程序。我不知道这些例子是做什么的。你能给我这个ca.success函数的确切代码吗?请看我更新的帖子。我已经包括了
SetAccountStatus
操作。在您的操作中,您明确地告诉服务器执行重定向。如果希望客户端页面不重新加载,为什么要这样做?那么如何使此操作不重新加载?我的任务是“编辑”已经编码好的web应用程序。我也不知道这些人都做了些什么。