jquery - Couldn't call server side method using Ajax -
i using 3-tier architecture demo application.
i trying call business logic layer method presentation layer using ajax. showing error. think there mistake in passing url.
here ajax call index.aspx page in presentation layer:
$.ajax({ type: "get", url: "demoapplication.bll/bll/showdetail", contenttype: "application/json; charset=utf-8", datatype: "json", data: { }, success: function (msg) { alert("data received"); }, error: function () { alert("couldn't proceed"); } });
here method in business logic layer:
namespace demoapplication.bll { public class bll { public static list<user> showdetail() { dal.dal dal = new dal.dal(); return dal.showdetail(); } } }
i think little bit confused, if trying call middle-tier method browser, there wrong. think of implications if supported. in business logic layer might have methods never exposed presentation layer. perhaps dropclientdatabase() used end maintenance tool. if directly call method through javascript? mean little bit of html , javascript skills call dropclientdatabase() , cause lot of problems users. since method @ bll layer, it's conceivable doesn't kind of authentication checking directly (that might precondition of calling it), poof, can drop databases. not want that.
we need explicitly define methods can called ajax partly security means. list<user> showdetail()
method in business layer should called presentation layer code (aspx.cs) this
[webmethod] public static list<user> showdetail() { //call method var myvar = bll.showdetail(); //this return list in json format return myvar; }
once did this, can call js using pagemethods or try changing url this
url: "yourpagename.aspx/showdetail",
Comments
Post a Comment