Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Ajax jQuery JSONP
Hi all,
 
I am using the script below but it s not redirecting the page.
 
string rdpConnect = "function btnShowID_onclick(){" +
            "if(document.getElementById('MainContent_ctl00_txtBeginDateID').value!='' && document.getElementById('MainContent_ctl00_txtEndDateID').value!='' && document.getElementById('MainContent_ctl00_ddlAuditorsID').value!='' )" +
            "{" +
                    //"alert($('#ContentPlaceHolder1_ucSample_txtName').val());" +
                "$.ajax({type: 'POST'," +
                "url: '~/WebService.asmx/Navigatetopage'," +
                "data:  '{zip:jhg}'," +
                "contentType: 'application/json; charset=utf-8'," +
                "dataType: 'json'," +
                "success: function(msg) {" +
                    "if(msg.d=='True'){" +
                            //"window.location.href='~/ReportPage/ReportViewerForAll.aspx?&ReportName=" + _reportName + "';" +
                            "window.location.href='Default.aspx'"+
                        "}" +
                    "}" +
                 "});" +
              "}" +
 
            "else" +
            "{" +
                "alert('Please Enter The Required Field(s)');" +
                "return false;" +
            "}" +
            "}";
 

                rdpFunctions.InnerHtml = rdpConnect;
                this.Controls.Add(rdpFunctions);
                flag = false;
            }
 

Any idea or help is higly appreciated.
Thanks in advance
 
Shafik
Posted 8-Jan-13 6:10am
Shafik487
Edited 8-Jan-13 6:20am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

What if the condition is true, but the ajax call isn't a succes? This would not show. Try to add code for the error situation, like this:
$.ajax({
    url: ...,
    data: ...,
    dataType: 'json',
    type: 'POST',
    timeout: 10000,
    success: function(json){
      //some code
    },
    error: function(jqXHR, textStatus, errorThrown){
      //some code
    }
 });
 
Good luck!
  Permalink  
Comments
Shafik at 8-Jan-13 12:39pm
   
Thanks for your Anser 1000 times. Now my code lool loke below:
 
function btnShowID_onclick()
{
if(document.getElementById('MainContent_ctl00_txtBeginDateID').value!='' && document.getElementById('MainContent_ctl00_txtEndDateID').value!='' && document.getElementById('MainContent_ctl00_ddlAuditorsID').value!='')
{
$.ajax({
url: '~/WebService.asmx/Navigatetopage',
data: '{zip:jhg}',
dataType: 'json',
type: 'POST',
timeout: 10000,
success: function(json)
{
window.location.href='Default.aspx';
return true;
},
error: function(jqXHR, textStatus, errorThrown)
{
alert('Please Enter The Required Field(s)');
return false;
}
});
}
}
 
But stil i am getting only error message.its not going to default.aspx
Can you plz tell me where i suppose to change my code.
 
Thanks
Shafik
E.F. Nijboer at 14-Jan-13 8:39am
   
Have you looked at the parameters of the error function? They should give you more info about what is going on.

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

  Print Answers RSS
0 OriginalGriff 6,803
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,421
3 Manas Bhardwaj 4,841
4 Maciej Los 4,330


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 8 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100