开发者

MVC.net noob question about Ajax and Json

I have a beginner level Json question with MVC.net (I've never really used jquery or json) so please excuse me if开发者_开发问答 I ask something stupid.

I have a javascript file with the below

<script>
    function refreshMovies() {
        //$.getJSON("/Home/Refresh", showMovies);
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "/Home/Refresh",
            success: showMovies
        });
    }

    function showMovies(movie) {
        var frag = "<ul>";
        frag += "<li>" + movie[0] + " - " + movie[1] + "</li>";
        frag += "</ul>";         
        alert(frag);
        $("#divMovies").html(frag);
    }
</script>

My Home controller looks like:

public ActionResult Refresh()
{            
        return Json(GetMovies());   // Method Returns IList<Movies>
}

The question I have is the frag on the alert and when the UL is displayed on the page is always empty.

However, firebug does show that the post request is returning the json, so maybe something is going wrong with showMovies()?


You say that firebug reports that you are getting your JSon correctly, otherwise I'd ask you whether you decorated the action with [HttpPost], as you are using the POST method.

Does the alert() currently display the correct HTML? If so, does the div have the id="divMovies" attribute (note, no # character here!).

Otherwise, try to move the alert() on top of the showMovies: does it show anything?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜