c# - jQuery Calling an ASMX Web Service that Returns Data -
i using jstree organize pages created users. upon right-clicking , pressing "rename" want fire js function hits function in code behind without post (if possible). want grab whichever item's i'm on id , rename in database , update jstree.
here sample code-behind function:
[system.web.services.webmethod] protected void renamepage(object sender, eventargs e) { datatable dt = new datatable(); using (sqlconnection con = new sqlconnection(global.constring)) { con.open(); using (sqlcommand cmd = new sqlcommand("contentpageupdate", con)) { cmd.parameters.add("@title", sqldbtype.varchar).value = global.safesqlliteral(txtpage.text, 1); cmd.commandtype = commandtype.storedprocedure; cmd.executenonquery(); } con.close(); //update content page repeater using (sqlcommand cmd = new sqlcommand("contentpagegetall", con)) { using (sqldataadapter da = new sqldataadapter(cmd)) { da.fill(dt); } } } }
don't think of jquery hitting c# functions, rather jquery hitting resource identified uri.
when make ajax request jquery, give url of destination , standard httprequest url. can page (webforms) or controller action (mvc).
since looks you're using webforms, make new page handle request. if put breakpoint in page_load
method you'll see gets fired when invoke ajax method:
in javascript right click can use jquery's ajax
method so:
$.ajax('mypage.aspx');
in mypage.aspx:
public void page_load(object sender, eventargs e) { response.write("you called me!"); }
you can response written adding few arguments $.ajax
call:
$.ajax('mypage.aspx', { success: function(data, textstatus, jqxhr) { alert(data); }});
Comments
Post a Comment