CoffeeCode
CoffeeCode

Reputation: 4314

issues with ajax calls from js file in asp.net mvc 3

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?

Upvotes: 2

Views: 308

Answers (1)

Har
Har

Reputation: 5004

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?

Upvotes: 1

Related Questions