[英]Jquery call to Controller of MVC: ReferenceError: url is not defined
I tried all my efforts, but just can't understand where the error lies. 我尽了所有努力,但是根本不明白错误在哪里。 I searched the google also but did not find any good solution.
我也搜索了谷歌,但没有找到任何好的解决方案。 It is not actually calling the controller/action in mvc.
它实际上不是在mvc中调用控制器/动作。 The same is running good in the other parts of the project.
在项目的其他部分也是如此。
I have a contrller "RB" under a folder "MVC", the action is defined as "SS". 我在文件夹“ MVC”下有一个控件“ RB”,操作定义为“ SS”。 and I am firing following code from my javascript file :
并且我从我的javascript文件中触发以下代码:
var sSch = function (request, response) {
var t = request.RF.substring(0, 1);
var d = new Date(request.RNR);
$.ajax({
url: "/MVC/RB/SS",
type: "POST",
dataType: "json",
data: {
_rId: request.ReportId,
_date: d.toString(),
_fcy: t
},
success: function (data) {
alert('Success');
},
error: function (data) {
alert('Error');
}
});
};
I am calling this function onClick of a button and properly getting the values in Request variable, but it is not anyhow calling the Controller/Action there. 我正在调用此函数的按钮onClick并正确获取Request变量中的值,但是无论如何都不能在那里调用Controller / Action。 On firebug I tested it throws the exception "ReferenceError: url is not defined".
在我测试过的萤火虫上,它引发了异常“ ReferenceError:URL未定义”。 I am using MVC3 under VS 2010.
我在VS 2010下使用MVC3。
Please Help. 请帮忙。
You have to define your action properly instead of 您必须正确定义操作,而不是
url: "/MVC/RB/SS",
use 采用
url: @Url.Action("SS", "RB")
For the url you have 'MVC/RB/SS' this is relative to your current directory a quick test would be to put in url: "../MVC/RB/SS" or url: "../../MVC/RB/SS" depending on how deep you page is in the site structure. 对于您具有“ MVC / RB / SS”的网址,这是相对于您当前目录的网址,快速测试方法是将网址:“ ../ MVC / RB / SS”或网址:“ ../../ MVC”放入网址/ RB / SS”,具体取决于页面在网站结构中的深度。
Another way would be to try this: 另一种方法是尝试这样做:
url: "@Action("/MVC/RB/SS")",
this will create the correct url at the correct level for you and should be picked up. 这将在正确的级别为您创建正确的url,应选择该URL。
Try this: 尝试这个:
url: "~/MVC/RB/SS",
This will resolve to path "http://site-name/MVC/RB/SS". 这将解析为路径“ http:// site-name / MVC / RB / SS”。
What does Firebug say? 萤火虫怎么说?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.