7

I'm trying to render a partial view in a container div using JQuery Ajax. Here's my ajax-call:

var href = {
    href: $(this).attr("href").substr(1)
}
var container = $(".customer-main-content-container");
$.ajax({
    url: "@Url.Action(" CustomerMenuSelection ")",
    type: "POST",
    dataType: "html",
    contentType: "application/json",
    data: JSON.stringify(href),
    error: function (jqXHR, textStatus, errorThrown) {
        alert("ERROR: " + errorThrown.text());
    },
    success: function (result) {
        container.empty();
        container.html(result).show();

    }
});

Update

Here's my Action code:

public ActionResult CustomerMenuSelection(string href)
{
    var user = GetCurrentUser();
    var tempSensorTree = _prtgClient.GetPrtgSensorTree(user.TempPrtgGroupId.ToString());
    var tempDevices = tempSensorTree.Sensortree.Nodes.Group.Device;

    return PartialView("_Monitor", tempDevices);
}

I've followed the call through my Action and found that it indeed sends all the correct data back to the view. However, my ajax-call is not running either error- or success-callback and I have no idea why. This is happening when clicking a menu-item, and this same ajax-call works for all other menu-items except this one. I can't find any differences between the pages. No errors are thrown, the data that I populate the view with is correct. My ajax-call just stops.

So in short, why is my callbacks not triggered?

Grateful for any assistance! Thanks in advance Martin Johansson

8
  • 1
    Did you look at the request using Fiddler or the browser's built in Network Inspector? Do you get an internal server error on that particular view? You could also try adding a complete callback on the $.ajax call to see if it gets triggered. Commented Jun 8, 2015 at 7:25
  • I saw now after waiting for a long while that I got a Connection Refused error in my browser, but I can't find anything about it in Fiddler. Commented Jun 8, 2015 at 7:30
  • Tushar "this" should be my menu-button. The script is in a click-event. Commented Jun 8, 2015 at 7:31
  • Have u put breakpoint on action "CustomerMenuSelection" and checked if code is getting executed properly? Commented Jun 8, 2015 at 7:37
  • @Tushar ok, well I'm getting the correct values from it atleast. I'm not very good at scopes in js. Commented Jun 8, 2015 at 7:38

1 Answer 1

1

This issue might be occurring because of dataType you are expecting from server. Try changing it to "html" as you are returning partial view from server.

dataType: "html"
Sign up to request clarification or add additional context in comments.

8 Comments

I used "html" before I started testing. The same issue occurs I'm afraid.
Have u put breakpoint on both success and error, or console some value in both callback and checked?
Yes, I've put breakpoints in both error and success, I've put alerts in both and I've checked console and I just get Connection Refused after a few minutes.
when I set timeout: 5000 it hits this timeout and runs the error function. Results in an alert "ERROR: timeout"
How long? at 30 sec it still hits the timeout
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.