Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using below code to my project its working fine. but some times i am loading same page four or five times the data will not return it will shows readystate 0 or undefined and am use this code in same domain not cross domain but i cant get exact error. please tell me if any one solved before this error

C#
Html page .

$(document).ready(function () {
       first();
      
   });


function first() {

        var firstajaxcall = null;
        firstajaxcall = $.ajax({
           type: "POST",
           contentType: "application/json; charset=utf-8",
            url: "webservice/ws_home.asmx/load_lender_list",
            data: "{}",
            dataType: "json",

            success: function (setvalue) {
             
            },
            failure: function () {
                //alert("failure");
            },
            error: function (response) {
                 alert("error" + response.d);
            }
        });
    }



C#
<big>Webservice file</big>

[WebMethod]
    public borrowercls[] load_borrower_list()
    {
        string query = string.Empty;
        con.mycon();
        List<borrowercls> lt_brlist = new List<borrowercls>();
        query = "select bloan.borrower_id, bloan.bor_purpose, bloan.bor_amount, bloan.interest, bloan.loan_duration from borrower_required_loan_details bloan, borrower_pdetails bpdetails where bpdetails.profile_agreed='1' and bloan.borrower_id = bpdetails.borrower_id";
        DataTable dt = dtdal.dt_return(query);
        if (dt.Rows.Count > 0)
        {
            foreach (DataRow dr in dt.Rows)
            {
                borrowercls hlist = new borrowercls();
                hlist.brid = dr["borrower_id"].ToString();
                hlist.br_amount = dr["bor_amount"].ToString();
                hlist.br_purpose = dr["bor_purpose"].ToString();
                hlist.br_interest = dr["interest"].ToString();
                hlist.br_duration = dr["loan_duration"].ToString();
                hlist.error = "true";
                lt_brlist.Add(hlist);
            }
        }
        else
        {
            borrowercls hlist = new borrowercls();
            hlist.error = "false";
            lt_brlist.Add(hlist);
        }
        return lt_brlist.ToArray();
    }


C#
public class borrowercls
{
    // Borrower
    public string brid { get; set; }
    public string br_amount { get; set; }
    public string br_interest { get; set; }
    public string br_month { get; set; }
    public string br_purpose { get; set; }
    public string br_duration { get; set; }

    // Error
    public string error { get; set; }
    public string err_msg { get; set; }
    // End
}
Posted
Updated 13-Dec-14 2:41am
v2
Comments
DamithSL 13-Dec-14 8:41am    
update the question with code of dt_return method
Gowtham B 13-Dec-14 8:44am    
This is my webmethod function

[WebMethod]
public borrowercls[] load_borrower_list()
{
string query = string.Empty;
con.mycon();
List<borrowercls> lt_brlist = new List<borrowercls>();
query = "select bloan.borrower_id, bloan.bor_purpose, bloan.bor_amount, bloan.interest, bloan.loan_duration from borrower_required_loan_details bloan, borrower_pdetails bpdetails where bpdetails.profile_agreed='1' and bloan.borrower_id = bpdetails.borrower_id";
DataTable dt = dtdal.dt_return(query);
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
borrowercls hlist = new borrowercls();
hlist.brid = dr["borrower_id"].ToString();
hlist.br_amount = dr["bor_amount"].ToString();
hlist.br_purpose = dr["bor_purpose"].ToString();
hlist.br_interest = dr["interest"].ToString();
hlist.br_duration = dr["loan_duration"].ToString();
hlist.error = "true";
lt_brlist.Add(hlist);
}
}
else
{
borrowercls hlist = new borrowercls();
hlist.error = "false";
lt_brlist.Add(hlist);
}
return lt_brlist.ToArray();
}
DamithSL 13-Dec-14 8:57am    
dt_return method code please?

1 solution

update the post method to get the error details, example code :
JavaScript
///       dataType: "json",
      url: "Default.aspx/DivideByZero",
      // Supply the Dividend value from our input field.
      data: "{ 'Dividend': '" + $("#Dividend").val() + "' }",
      // Error!
      error: function(xhr, status, error) {
        // Display a generic error for now.
        alert("AJAX Error!");
      }
    });
  });
});

http://encosia.com/use-jquery-to-catch-and-display-aspnet-ajax-service-errors/[^]
and also from the the web service side you can log the exceptions and check them later.
 
Share this answer
 
Comments
Gowtham B 13-Dec-14 8:55am    
Hi am using same like alert box but the problem is am not getting error instead of it will take some more time and retrieved data properly. some times the small function also take more time and returned data
DamithSL 13-Dec-14 9:01am    
may be your query take more time to retrieve data and also you need to handle the connections properly, ones you open connection to database you need to dispose it properly. you better log the service errors and check them to see what is the actual issue.

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