Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
pls help, it's not redirecting to a new page!

The home page
C#
$(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)

XML
<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>
Posted
Updated 25-Mar-12 6:08am
v10
Comments
ZurdoDev 23-Mar-12 14:57pm    
What happens when you debug it? Have you tried data.d instead of data.redirect?
[no name] 23-Mar-12 15:04pm    
What other page? Clarify where the code is being used.
skypoints 25-Mar-12 12:03pm    
Hi ryanb31.
it's still not working

1 solution

Debug your code by using keywords debugger; or alert('something');.

Something as below.
JavaScript
success: function (data, textStatus) {

                        if (data.redirect) {
                            /*Using debugger */
                            debugger;
                            /*Or using alert*/
                            alert(data.redirect);
                            window.location.href = data.redirect;
                        }
                        else {

                            $(&quot;#notification&quot;).replaceWith(data.form);
                        }


                    },


You may also refer below link discussing similar problem, where questioner solved the problem by specifying correct link/url.

http://forum.jquery.com/topic/jquery-jquery-location-href-or-load-problem
 
Share this answer
 
Comments
[no name] 25-Mar-12 11:36am    
Didn't answer the question. A useless generic answer.
RaisKazi 28-Mar-12 19:16pm    
It does not covers exact answer because question is not very clear. But I think it should have provided basic idea of JavaScript debugging to OP. By the way appreciate your down-vote with comment. Down-votes without comment makes no sense. Cheers - Rais

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900