Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

function error() { [native code]}

I have asp.net web site in c#.

On Dropdownlist Onchange() event i'm calling this jquery function, which throws:

function error(){[native code]}

 <script type="text/javascript">
     function GetDescription(a) {
         alert(a); // the dropdown item selected value
         var id = (!isNaN($(a).val())) ? parseInt($(a).val()) : 0;
         $.ajax({
             type: 'POST',
             contentType: "application/json; charset-8;",
             url: 'WT.aspx/GetRef',
             data: "{ 'id':'" + id + "'}",
             success: function (data) {
                 alert(data);
             },
             error: function (data) {
                 alert(Error);
             }

         });

     }
  </script>

WT.aspx/GetRef


     [WebMethod]
     public string GetRef(int id)
     {
         DataTable dt = new DataTable();
         SqlParameter[] p = new SqlParameter[1];
         p[0] = new SqlParameter("@RefID", id);
         dt = dl.GetDataWithParameters("Sp_WT_GetRef", p);

         string data = dt.Rows[0]["Description"].ToString() +"|"+ dt.Rows[0]["PriceInUSD"].ToString();

         return data;
     }

http://localhost:54576/resources/demos/style.css Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:54576/AutomobileWebApp/WT.aspx/GetRef Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://localhost:54576/resources/demos/style.css Failed to load resource: the server responded with a status of 404 (Not Found)

like image 281
user3185287 Avatar asked Jan 30 '26 09:01

user3185287


1 Answers

My first suggestion would be to make the method attributed as [WebMethod] to static.

[WebMethod]
 public static string GetRef(int id)
 {
     DataTable dt = new DataTable();
     SqlParameter[] p = new SqlParameter[1];
     p[0] = new SqlParameter("@RefID", id);
     dt = dl.GetDataWithParameters("Sp_WT_GetRef", p);

     string data = dt.Rows[0]["Description"].ToString() +"|"+ dt.Rows[0]["PriceInUSD"].ToString();

     return data;
 }

If that didn't work out, try to check whether your ajax url is pointing to the method correctly.

url: 'WT.aspx/GetRef',

and also check whether you are passing 'this' as the function parameter for GetDescription(a).

 <select onchange="GetDescription(this)">
    <option value="1">text1</option>
    <option value="2">text2</option>
    <option value="3">text3</option>
 </select>
like image 52
richard-lambert Avatar answered Feb 02 '26 01:02

richard-lambert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!