Making AJAX call back in ASP.NET with jQuery

痴心易碎 提交于 2019-12-11 08:15:32

问题


I accept both C# and VB.NET

If you visit this http://www.eol.org/pages/983558 and then click on the link like the image below you'll see in-line pop-up DIV which displays a busy status of Ajax callback before it displays the information. So, the information is not there yet until you click on the link.

I'd like to do the same but ASP.NET and jQuery. If there's any place to help me get started on the right track? Thanks.


回答1:


Using jQuery to directly call ASP.NET AJAX page methods

$.ajax({
  type: "POST",
  url: "PageName.aspx/MethodName",
  data: "{}",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function(msg) {
    // Do something interesting here.
  }
});

I think this is probably a good place to start.




回答2:


yes u can use roberts code to send ajax request to server side code and additionally u can use beforeSend callbck function where u will display ur hidden div with loading.. message and in success function u will actually put the data into that div.

$.ajax({
  type: "POST",
  url: "PageName.aspx/MethodName",
  data: "{}",
  beforeSend: function()
  {
     //display hidden div with loading.. message
  },
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function(msg) {
    // remove loading.. message and put actual data to the div
  }
});

u can use error callback to display error message in the same div if ajax call fails for some reason. u can learn more about $.ajax function here



来源:https://stackoverflow.com/questions/3882628/making-ajax-call-back-in-asp-net-with-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!