Hi,
Is it possible to call a method in the JavaScript?
The method is not a web method.i.e please look the method bellow
public static string LoadData()
{
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
SqlDataAdapter da = new SqlDataAdapter("select * from Employee", cn);
DataSet ds = new DataSet();
da.Fill(ds);
return JsonConvert.SerializeObject(ds.Tables[0]);
}
I need to call this method in script. I have done with we method but our manager is not accepting because If we declare method as a web method it exposed so that I need to call direct method in script i.e JQGrid Script.Please look the script
<pre lang="cs">$(document).ready(function () {
$.ajax({
url: "Default1.aspx/LoadData",
datatype: "json",
data: "{}",
contentType: "application/json; charset=utf-8",
method: "POST",
success: function (result) {
result = result.d;
jQuery("#EmpTable").jqGrid
({
datatype: "local",
colModel: [
{ name: 'Id', index: 'Id', width: 50 },
{ name: 'FirstName', index: 'FirstName', width: 150 },
{ name: 'LastName', index: 'LastName', width: 150 },
{ name: 'Last4ssn', index: 'Last4ssn', width: 60 },
{ name: 'Department', index: 'Department', width: 80 },
{ name: 'Age', index: 'Age', width: 50 },
{ name: 'Salary', index: 'Salary', width: 80 },
{ name: 'Address', index: 'Address', width: 150 },
{ name: 'MaritalStatus', index: 'MaritalStatus', width: 100 }
],
data: JSON.parse(result),
rowNum: 2,
loadonce: true,
rowList: [2, 5, 10],
pager: '#EmpPager',
viewrecords: true,
sortname: 'id',
gridview: true,
sortorder: 'desc',
mtype: 'GET',
height: "auto",
caption: "List Employee Details",
editurl: "Default1.aspx/LoadData"
});
$('#EmpTable').jqGrid('navGrid', '#EmpPager',
{
edit: true,
add: true,
del: true,
search: true,
searchtext: "Search",
addtext: "Add",
edittext: "Edit",
deltext: "Delete"
}, { closeOnEscape: true, reloadAfterSubmit: true,
drag: false
});
}
});
});</pre>
If You don't Know the jqGrid leave it the jqGrid script. In general script how we can call.
Thanks,
Purna