简体   繁体   English

我不想回发我的.aspx页面

[英]I don't want to postback my .aspx page

I want to go from the First.aspx page to the second.aspx page without postback. 我想从First.aspx页转到second.aspx页而无需回发。 How should I handle this situation? 我应该如何处理这种情况? Is it possible or not? 有没有可能? I am doing this, but I don't know how to get a response from the handler. 我正在执行此操作,但是我不知道如何从处理程序中获取响应。

Sending a request to handler: 向处理程序发送请求:

<script type="text/javascript" src="jqure.js"></script>
 function goMoz() { 
      $.post("Handler1.ashx", callback);
      function callback(data) { 
      alert(data);
    }
</script>

In the body of the html I'm using html <a id="buton" onclick="goMoz()"> 在html的正文中,我使用的是html <a id="buton" onclick="goMoz()">

What must I do in the handler to go to the second.aspx page? 我必须在处理程序中执行什么操作才能转到second.aspx页?

I am also using window.location = "Registration.aspx"; 我也在使用window.location = "Registration.aspx"; in goMoz() . goMoz()

A few things: first, your javascript example code has syntax errors, you're missing a closing }. 有几件事情:首先,您的javascript示例代码有语法错误,您缺少}。

Second: If you want to load the content of a different page and use the content inside the current page, check out the different Ajax functions in jquery, for example the load : 第二:如果要加载其他页面的内容并使用当前页面内的内容,请在jquery中检查不同的Ajax函数 ,例如load

   function goMoz() {
       $.post("Handler1.ashx", callback);

       function callback(data) {
           alert(data);
           // Load response of "second.aspx" 
           // into element with ID results.
           $("#results").load("second.aspx");
       }
   }

Note that you should be careful when loading a "whole page" into an element of the current page. 请注意,将“整个页面”加载到当前页面的元素中时应小心。 If the "whole page" contains full HTML markup with html, body etc. tags then your HTML can easily become invalid. 如果“整个页面”包含带有html,body等标记的完整HTML标记,则您的HTML可能很容易变得无效。 You can however define what part of the page to actually grab and insert in the current page by adding a selector after the url: 但是,您可以通过在url之后添加选择器来定义要实际抓取并插入当前页面的页面的哪一部分:

$("#results").load("second.aspx #whatToLoad");

This would only load the content of whatToLoad element in the results element on the current page. 这只会在当前页面的results元素中加载whatToLoad元素的内容。

in aspx page 在aspx页面

 function goMoz(islem) {
            $.ajax(
                {
                    type: "POST",
                    url: "../Handler1.ashx",
                    data: "islem=" + islem,
                    dataType: "html",
                    success: function (data) {

                      alert(data)

                    },
                    error: function (data) {
                        alert("Error")
                    }
                });
        };

in ashx handeler. 在ashx handeler中。

  public void ProcessRequest(HttpContext context)
        {
            string isl= context.Request.Form["islem"];
             .....same codes
            context.Response.Write("return values");


          }

Hope it helpful 希望对您有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM