本文介绍了操作结果未在控制器中调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 嘿伙计们在尝试在MVC中的外部js文件中进行ajax调用时遇到问题。我试图在我的控制器中调用JSONResult方法。 ajax命中成功函数,但我的JSON结果永远不会被击中。有人可以指出我正确的方向。 cshtml中用于保存控制器路径的隐藏字段 < 输入 类型 = hidden value = @ Url.Action( GetNetworkData, NetworkSetting) id = NetworkData / > Js档案 var url = $(' #NetworkData')。val(); // alert(url); var url = $(' #NetworkData')。data(' url'); $ .ajax({ url:url, cache: false , type:' GET', contentType:' application / json; charset = utf-8', data:{}, success: function (data){ alert(' success'); } }); [HttpGet] public JsonResult GetNetworkData() { string s = 这里将返回数据; return Json(s,JsonRequestBehavior.AllowGet); } 我知道传递给ajax调用的url是正确的,就像我直接粘贴它一样它被调用的URL。非常感谢任何帮助。 谢谢.. 解决方案 (' #NetworkData')。val(); // alert(url); var url = (' #NetworkData' )。data(' url'); .ajax({ url:url, cache: false , type:' GET', contentType:' application / json; charset = utf-8', data:{}, success: function (数据){ alert(' success'); } }); [HttpGet] public JsonResult GetNetworkData() { string s = 这里将返回数据; return Json(s,JsonRequestBehavior.AllowGet); } 我知道传递给ajax调用的url是正确的,就像我直接粘贴它一样它被调用的URL。非常感谢任何帮助。 谢谢.. Hey guys I have an issue while trying to make an ajax call in an external js file in MVC. I am trying to call a JSONResult method in my controller. The ajax hits the success function but my JSON result never gets hit. Can someone point me in the right direction.Hidden field in cshtml to hold the path to the controller<input type="hidden" value="@Url.Action("GetNetworkData", "NetworkSetting")" id="NetworkData" />Js Filevar url = $('#NetworkData').val(); // alert(url); var url = $('#NetworkData').data('url'); $.ajax({ url: url, cache: false, type: 'GET', contentType: 'application/json; charset=utf-8', data: {}, success: function (data) { alert('success'); } });[HttpGet] public JsonResult GetNetworkData() { string s = "Will return data here"; return Json(s, JsonRequestBehavior.AllowGet); }I know the url passed to the ajax call is correct as when I paste it directly in the URL it gets called. Any help is very much appreciated.Thanks.. 解决方案 ('#NetworkData').val(); // alert(url); var url =('#NetworkData').data('url');.ajax({ url: url, cache: false, type: 'GET', contentType: 'application/json; charset=utf-8', data: {}, success: function (data) { alert('success'); } });[HttpGet] public JsonResult GetNetworkData() { string s = "Will return data here"; return Json(s, JsonRequestBehavior.AllowGet); }I know the url passed to the ajax call is correct as when I paste it directly in the URL it gets called. Any help is very much appreciated.Thanks.. 这篇关于操作结果未在控制器中调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-28 02:43