JQuery Ajax call gives 404 'Resource Not Found' Error but normal URL call is fine

前端 未结 7 2454
别跟我提以往
别跟我提以往 2020-12-31 18:29

I have a weird problem when using JQuery call in my ASP.NET MVC project. I found that the Ajax call gives 404 ( resource not found error). But when I use the usual URL GET c

7条回答
  •  不思量自难忘°
    2020-12-31 19:00

    I fix this problem by using FireBug to show me the request that was generated by JQuery. To my amazement, the url generated is

    http://localhost/ViewRecord/ViewRecord/GetSoftwareChoice?username=123
    

    for the JSON call:

    $(function() {
    $("#username").click(function() {
            $.getJSON("ViewRecord/GetSoftwareChoice", {username:'123'},
        function(data) {
            alert(data);
        });
        });
    });
    

    So I just have to change the $.getJSON line to

    $.getJSON("GetSoftwareChoice", {username:'123'},
    

    Alternatively, use the forward slash:

     $.getJSON("/ViewRecord/GetSoftwareChoice", {username:'123'},
    

提交回复
热议问题