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?

10
  • What is the value passed as url and what are the relativepaths to your view and scripts?CommentedMar 20, 2012 at 14:15
  • yes, it is a relative path, but it is formed correctly + it stops on the breakpoint in the actionCommentedMar 20, 2012 at 14:40
  • Can you set a breakpoint in the error handler and see if it gets hit? If not, are there any javascript errors reported in the console?CommentedMar 20, 2012 at 14:43
  • Are you getting any script errors ? what is the value of url varibale ?
    – Shyju
    CommentedMar 20, 2012 at 14:49
  • Can you include the HTML that is using the script?CommentedMar 20, 2012 at 14:51

1 Answer 1

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?

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.