jquery - Can C# MVC act as standalone web api service? -
lately i've been having problems returning json responses php , jquery based url. use post request as:
$(document).ready(function() { (function(){ console.log("ran"); $.ajax({ type: "get", url: "https://chad-test4.clas.university.edu/employees/edit/22", datatype: "json", success: function (data) { console.log("response recieved"); console.log("success: " + data); empdata = data; }, error: function() { console.log("failed"); } }); })(); });
my controller is:
public jsonresult edit(int? id) { if (id == null) { return json("error: id not exist", jsonrequestbehavior.allowget); } employee chad = db.employees.find(1); if (chad == null) { return json("error: employee not exist", jsonrequestbehavior.allowget); } chad.last_name = "changed"; chad.netid = "1111111"; db.entry(chad).state = entitystate.modified; db.savechanges(); console.writeline("successfully gotten"); return json(chad, jsonrequestbehavior.allowget); }
this keeps either returning full html page, or error following console log:
uncaught typeerror: $(...).alert not function(anonymous function) @misc.js:633 display:410 ran misc.js:783 uncaught typeerror: cannot read property 'elements' of undefinedcalculatetotalpurposesamount @ misc.js:783window.onload @misc.js:627 display:421 failed
do need instead make web api project jquery data returned?
Comments
Post a Comment