tags:

views:

29

answers:

2

I'm attempting to fire off a JQuery .get() to a MVC (2 rc 2) controller. I can see the JS function call happen, then when the .get() is called it never comes back.

(1) It would be great to know what I'm doing wrong to fix the immediate problem

(2) It would also be great to have an education on what to do for debugging these async requests clientside... what would the next step be to track what is happening when .get() fires?

the JQuery:

function getWeather() {
    var URL = "/Home/GetData/3"
    $.get(URL, function (data) { $("#Result").html(data); });
}

should be calling my calling my HomeController GetData() method with the arg '3'. here is my HomeController GetData method... I never see a breakpoint set here get hit, so whatever I'm doing in the method is so far irrelevant...it's not getting called.

[HandleError]
public class HomeController : Controller
{
    public ActionResult GetData(Int32 i)
    {
        Response.Write("<h1>data</h1>");
        return null;
    }
}
A: 

Use FireBug to see if an asynchronous request is sent to the server and what does the server respond. Also change your controller action to:

public ActionResult GetData(Int32 i)
{
    return Content("<h1>data</h1>", "text/html");
}

Also you forgot to put a ; at the and of your URL javascript variable declaration.

Darin Dimitrov
A: 

You can simplify your jQuery:

function getWeather() {
    $("#Result").load(URL, "/Home/GetData/3");
}

Also, you need to fix your GetData method, as Darin Dimitrov suggested in his answer.

Meanwhile, check your routes to ensure that you have one that would cover the /Home/GetData/3 URL.

Franci Penov