开发者

Using POST in jQuery with ASP.NET MVC

I the site is on the follo开发者_Go百科wing 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). The site loads fine, just when it comes to jQuery's $.post() I encoutered a problem. The jQuery code looks like this:

$("#predmet").change(function () {
    $("#predmet option[value='prazen']").hide();
    $.post("/VnosPrijavnica/PoisciRoke", $("#kriteriji").serialize(), function (data) {
        $("#roki").html(data);
    });
});

The $.post() never executes. I noticed if I change the URL to localhost:xxxx/VnosPrijavnica this piece of jQuery code works as intended. 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?


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);
    });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜