javascript - function error() { [native code]} -
i have asp.net web site in c#.
on dropdownlist onchange()
event i'm calling jquery function, throws:
function error(){[native code]} <script type="text/javascript"> function getdescription(a) { alert(a); // 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 load resource: server responded status of 404 (not found) http://localhost:54576/automobilewebapp/wt.aspx/getref failed load resource: server responded status of 500 (internal server error) http://localhost:54576/resources/demos/style.css failed load resource: server responded status of 404 (not found)
my first suggestion make method attributed [webmethod] 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 didn't work out, try check whether ajax url pointing method correctly.
url: 'wt.aspx/getref',
and check whether passing 'this' function parameter getdescription(a).
<select onchange="getdescription(this)"> <option value="1">text1</option> <option value="2">text2</option> <option value="3">text3</option> </select>
Comments
Post a Comment