Hold On

Hold On

  • 1.2k
  • 706
  • 65.7k

Calling aspx page method using jquery

Aug 15 2019 3:29 AM
I want to call a function from my code behind (C#) using Jquery but no luck. Below is my code behind function and my jquery:
 
  1. [System.Web.Services.WebMethod]  
  2.         public static VmLowestLatestPrice LowestLatestPrice(string carMake, string carModel, string partsCode)  
  3.         {  
  4.             using (SqlConnection con = DBCS.DBCon())  
  5.             {  
  6.                 SqlCommand cmd = new SqlCommand("spClaims_GetLowestLatestPrice", con);  
  7.                 cmd.CommandType = CommandType.StoredProcedure;  
  8.                 cmd.Parameters.AddWithValue("@carMake", carMake);  
  9.                 cmd.Parameters.AddWithValue("@carModel", carModel);  
  10.                 cmd.Parameters.AddWithValue("@partsCode", partsCode);  
  11.   
  12.                 con.Open();  
  13.                 SqlDataReader rdr = cmd.ExecuteReader();  
  14.                 while (rdr.Read())  
  15.                 {  
  16.                     VmLowestLatestPrice price = new VmLowestLatestPrice();  
  17.                     price.LowestPrice = Convert.ToDouble(rdr["LowestPrice"]);  
  18.                     price.LatestPricePurchase = Convert.ToDouble(rdr["LatestPricePurchase"]);  
  19.                     return price;  
  20.                 }  
  21.   
  22.                 rdr.Close();  
  23.                 return null;  
  24.             }  
  25.         }  
  1. <script type="text/javascript">  
  2.         $(document).ready(function () {  
  3.             $('#<%=ddlDamageName.ClientID %>').change(function () {  
  4.                 var partsCode = $('#ddlDamageName option:selected').val();  
  5.                 var make = $('#lblMake').val();  
  6.                 var model = $('#lblModel').val();  
  7.                 $.ajax({  
  8.                     url: 'create-quotation.aspx/LowestLatestPrice',  
  9.                     method: 'post',  
  10.                     conttentType: 'application/json',  
  11.                     data: '{carMake: ' + make + ', carModel: ' + model + ', partsCode: ' + partsCode + '}',  
  12.                     dataType: 'json',  
  13.                     succes: function (data) {  
  14.                         $('#lblLowest').val(data.d.LowestPrice);  
  15.                         $('#lblLatest').val(data.d.LatestPricePurchase);  
  16.                     },  
  17.                     error: function (error) {  
  18.                         alert(error);  
  19.                     }  
  20.                 });  
  21.             });  
  22.         });  
  23.     </script>  
 My jquery version is 3.0.0.
 
Thanks for any possible assistance. 

Answers (19)