I'm very new in javascript, I have a problem, I have a external js file which I need to run some c# server side codes. my external js file is something like:
my.login = function(parameter, callback) { if(someCondition) { alert("you cant progress") } else { //not importent logic } } I considered two ways for preparing some condition one of them with ajax call:
$.get("locallhost:2756/myCont/MyAct?Id=" + Id + "", function(response) { if (!response.result) { alert("you cant progress"); } but I get the error $ is not defined another option is using XmlHttpRequest like this:
var xhReq = new XMLHttpRequest(); xhReq.open("POST", "locallhost:2756/myCont/MyAct?Id=" + Id + "", true); xhReq.send(Id); var res = xhReq.response; var stat= XMLHttpRequest.status; var resText= xhReq.responseText; but I get nothing in resText its "", My controller and action are also like this:
public class myContController : Controller { [HttpPost] public JsonResult MyAct(string Id) { if (Logic.ValidateId(Id)) { return Json(new { result = true }); }; return Json(new { result = false }); } } all I want is validate something in c# and return the result if it's ok or not to javascript, If there is another way, would you please help me?
EDIT: I know I can reference jquery in html files to avoid $ not defined but this is external js that others can use it which they are not in my projects. I need to do something with that external js