[英]Easy Async Callback Alternative
I need help with my logic... 我的逻辑需要帮助...
Currently: 目前:
The problem with the above is the reloading of the webpage. 上面的问题是网页的重新加载。 I do not want that. 我不要那个。 I have played around with a callback script that is not working (I have another question open on trying to debug that). 我玩了一个不起作用的回调脚本(尝试调试该脚本时还有另一个问题)。
My question is about alternatives to accomplish my steps as defined above without a callback or postback? 我的问题是关于在没有回调或回发的情况下完成上述步骤的替代方案? Is there a way to simply call the server-side function on demand from a client side function? 有没有一种方法可以根据需要从客户端函数简单地调用服务器端函数? (I know callbacks should do this very thing, but mine is not working) (我知道回调应该做这个事情,但是我的工作不正常)
If there is no such alternative, why is it that callbacks are so complicated (from a novice's point of view)? 如果没有其他选择,为什么回调是如此复杂(从新手的角度来看)? Why can I not simply call a callback like: 为什么不能简单地像这样调用回调:
if (IsCallBack)
{
string test = Request.Form["saveTest"];
//do stuff
}
Thank you. 谢谢。 Also, please do not 'close' or mark down my question without first critiquing me. 另外,请先“批评”我,然后再“关闭”或写下我的问题。 Thanks. 谢谢。
Here's the simplest example I can think of, that uses Ajax with ASP.Net. 这是我能想到的最简单的示例,该示例将Ajax与ASP.Net结合使用。
First, UserInput.aspx 首先,UserInput.aspx
<html>
<input type='text' id='SomeUserInput' />
<input type='submit' value='submit' id='SubmitButton' />
<script src='http://code.jquery.com/jquery-1.10.2.js'></script>
<script>
// wait for the document to load
$(document).ready(function() {
// handle the button click
$("#SubmitButton").on("click", function(e) {
// stop the page from submitting, so we can make the Ajax call
e.preventDefault();
// retrieve the user input
var userInput = $("#SomeUserInput").val();
// make the Ajax request
$.post("AjaxHandler.aspx", { saveText: userInput }, function(response) {
// handle response from the server
alert("Request is complete. Result: " + response);
});
});
});
</script>
</html>
Second, AjaxHandler.aspx 二,AjaxHandler.aspx
<%@ Page Language="C#" %>
<%
string userInput = Request.Params["saveText"];
// use the input here
Response.Write("done, maybe?");
%>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.