c# - Get all data from code-behind using AJAX -
i know question has been asked tens of times, question bit different.
i want send request using ajax code-behind retrieve records attached database, don't have parameters pass want send request , json object contains table data, , here difference in question questions i've seen included passing params.
here ajax code in i'm trying send request:
var data; $.ajax({ type: "post", url: "register.aspx/getrecords", datatype: "json", success: function (response) { console.log(response.d); data = response; }, error: function(xmlhttprequest, textstatus, errorthrown) { console.log("status: " + textstatus); console.log(" error: " + errorthrown); } });
and here code-behind i'm trying fetch data database:
[scriptmethod(responseformat = responseformat.json)] public static list<employee> getrecords() { sqlconnection con; sqlcommand cmd; sqldatareader reader; list<employee> datarows = new list<employee>(); con = new sqlconnection("data source=(localdb)\\mssqllocaldb;attachdbfilename=\"c:\\users\\shebel ali\\desktop\\sampledb.mdf\";integrated security=true;connect timeout=30"); con.open(); cmd = con.createcommand(); cmd.commandtext = "select * employee"; reader = cmd.executereader(); int i1 = 0; int i2 = 0; int i3 = 0; int i4 = 0; int i5 = 0; int i6 = 0; while (reader.read()) { employee getemp = new employee(reader.getvalue(i1).tostring(), reader.getvalue(i2).tostring(), reader.getvalue(i3).tostring(), reader.getvalue(i4).tostring(), reader.getvalue(i5).tostring(), reader.getvalue(i6).tostring()); i1++; i2++; i3++; i4++; i5++; i6++; datarows.add(getemp); } return datarows; }
plz ignore inproper ways code stuff, focus on error below
what happening i'm getting error ajax request, here error i'm getting:
status: parsererror.
error: syntaxerror: unexpected token < in json @ position 0.
any suggestions please?
Comments
Post a Comment