SignalR, Not a Function -
i trying send data sql server. model @ hand. got error saying addbug not function. post:29 uncaught typeerror: chat.client.addbug not function can please me in debugging error. cannot find mistake , sorry totally new signalr , trying somethings , running server.
client-side
<script src="~/scripts/jquery-1.10.2.min.js"></script> <script src="~/scripts/jquery.signalr-2.2.0.min.js"></script> <script src="~/signalr/hubs"></script> <meta name="viewport" content="width=device-width" /> <title>post</title> <script> var chat; $(document).ready(function () { chat = $.connection.additems; console.log('connection done'); $.connection.hub.start(); console.log('connection secured'); }); function test() { console.log('clicked'); var = { id: $('#txtid').val(), name: $('#txtname').val() }; console.log('finish a'); chat.client.addbug(json.stringify(a)); console.log('error'); }; </script>
my hub class
using system; using system.collections.generic; using system.linq; using system.web; using microsoft.aspnet.signalr; using webapitest2.models; using system.data.entity; using microsoft.aspnet.signalr.hubs; namespace webapitest2 { [hubname("additems")] public class queryhub : hub { public void addbug(test bug) { try { using (var db = new testdbentities()) { var b = db.tests.create(); b.id = bug.id; b.name = bug.name; db.tests.add(b); db.savechanges(); int id = b.id; clients.others.addbug(b); clients.caller.addmebug(b); } } catch (exception ex) { clients.caller.reporterror("unable create bug."); } } } }
controller
public actionresult post() { return view(); }
//hub code public void addbug(string id, string name) { //your code } //js server call window.chat.server.addbug($('#txtid').val(), $('#txtname').val());
Comments
Post a Comment