[英]Using POST in jQuery with ASP.NET MVC
I the site is on the following URL localhost:xxxx/VnosPrijavnica/Predmeti/123456
, where the VnosPrijavnica
is the controller, Predmeti
is an action in the controller, and 123456
is an optional param (everything is defined correctly in Global.asax). 我的网站位于以下URL localhost:xxxx/VnosPrijavnica/Predmeti/123456
,其中VnosPrijavnica
是控制器, Predmeti
是控制器中的操作, 123456
是可选参数(在Global.asax中正确定义了所有内容)。 The site loads fine, just when it comes to jQuery's $.post()
I encoutered a problem. 该站点可以很好地加载,就jQuery的$.post()
我遇到了一个问题。 The jQuery code looks like this: jQuery代码如下所示:
$("#predmet").change(function () {
$("#predmet option[value='prazen']").hide();
$.post("/VnosPrijavnica/PoisciRoke", $("#kriteriji").serialize(), function (data) {
$("#roki").html(data);
});
});
The $.post()
never executes. $.post()
永远不会执行。 I noticed if I change the URL to localhost:xxxx/VnosPrijavnica
this piece of jQuery code works as intended. 我注意到,如果将URL更改为localhost:xxxx/VnosPrijavnica
这部分jQuery代码将按预期工作。 The question is what must I modify in the jQuery code that it will work with the first URL as it does in the second? 问题是我必须在jQuery代码中进行哪些修改才能使其与第一个URL一起使用,就像在第二个URL中一样?
Try something like this: 尝试这样的事情:
var baseUrl = '<%= ResolveUrl("~/") %>';
$("#predmet").change(function () {
$("#predmet option[value='prazen']").hide();
$.post(baseUrl + "/VnosPrijavnica/PoisciRoke", $("#kriteriji").serialize(), function (data) {
$("#roki").html(data);
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.