在Ajax回调中重定向 [英] redirect in ajax callback

查看:97
本文介绍了在Ajax回调中重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助,它不会重定向到新页面!

主页

pls help, it''s not redirecting to a new page!

The home page

$(document).ready(function () {

            var ajaxUrl = "fetchcustomer.aspx";

            $("#Logbutton").click(function () {



                $.ajax({
                    type: "POST", //GET or POST or PUT or DELETE verb /* Tim hieu xem tai sao khng duoc */
                    url: ajaxUrl, // Location of the service

                    data: { ID: $('#TextBox1').val(),
                        ID2: $('#TextBox2').val()
                    }, //Data sent to server
                    contentType: "text/html; charset=utf-8", // content type sent to server
                    dataType: "json", //Expected data format from server

                    processdata: true, //True or False
                    success: function (data, textStatus) {

                        if (data.redirect) {
                       
                            window.location.href = data.redirect;
                        }
                        else {
                   
                            $("#notification").replaceWith(data.form);
                        }
                     

                    },
                    error: ServiceFailed// When Service call fails
                });


                return false;
            });





和另一页(提取)





and the other page (fetch)

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
      /* lấy connect string từ web.config, k để đường dẫn trên code */
      
        SqlConnection conn = new SqlConnection("Data Source=ASIA_ITS\\THAI;Initial Catalog=skyserver;Integrated Security=True");
    
        conn.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = conn;

        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "st_login_user"; /*procedure de truyen tham do */

        SqlParameter p1 = new SqlParameter("pr_email", "abc");
        SqlParameter p2 = new SqlParameter("pr_pass", "123456");
        p1.IsNullable = true;
        p2.IsNullable = true;
        p1.Direction = ParameterDirection.Input;
        p2.Direction = ParameterDirection.Input;

        cmd.Parameters.Add(p1);
        cmd.Parameters.Add(p2);
        
        /* lấy giá trị return từ SQL */
        
        SqlParameter returnValue = new SqlParameter("return", SqlDbType.Int); /*return la thma so tra ve tu SQL */
        returnValue.Direction = ParameterDirection.ReturnValue;
        cmd.Parameters.Add(returnValue);
        cmd.ExecuteNonQuery();
        int ret = Int32.Parse(cmd.Parameters["return"].Value.ToString());

        SqlDataReader read = cmd.ExecuteReader();

        switch (ret)
        {
           

            case 0:

                Response.Write("<p>Wrong Pass!</p>");
                
                break;

         

            case 1:

                Response.Redirect("Home_user.aspx");
                          
                break;
                
        }
        read.Close();
      
    }   
         
    
   
    
</script>

推荐答案

(document).ready(function(){ var ajaxUrl = " ;
(document).ready(function () { var ajaxUrl = "fetchcustomer.aspx";


(" ).click(function (){
("#Logbutton").click(function () {


.ajax({ 类型:" // GET或POST或PUT或DELETE动词/* Tim hieu xem tai sao khng duoc */ url:ajaxUrl,// 服务的位置 数据:{ID:
.ajax({ type: "POST", //GET or POST or PUT or DELETE verb /* Tim hieu xem tai sao khng duoc */ url: ajaxUrl, // Location of the service data: { ID:


这篇关于在Ajax回调中重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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