2

A have an ajax call that executes fine when it is placed in the .cshtml file, after moving the JS to the call stopped working. I did some debuging and it apeared that right action is beeing called and it returns correct data, but I dont enter the ajax success function in the JS.

The same applies to getJSON.

and also no error message is being displayed

here is the code:

$.ajax({
            type: "GET",
            cache: false,
            url: url,
            dataType: "json",
            success: function (data) {
               //...
            },error: function (xhr, ajaxOptions, thrownError) {
                alert(xhr.status);
                    alert(thrownError);
            }
            });
        }

//action:

[HttpGet]
    public JsonResult HasUpdates()
    {
        var hasUpdates = diagnosticManager.AgentHasUpdates();
        return Json(hasUpdates, JsonRequestBehavior.AllowGet);
    }

Am I missing some thing here?

CoffeeCode
  • 4,296
  • 9
  • 40
  • 55

1 Answers1

1

You may be getting success just a bit to late because of asynchronization Use a synchronous AJAX call look over here at the answer How can I get jQuery to perform a synchronous, rather than asynchronous, Ajax request?

Community
  • 1
  • 1
Har
  • 4,864
  • 2
  • 19
  • 22