0

I really don't know why but the function(response)-part won't be executed at all - although the Get Method in my Controller gets called by getJSON.

Script:

$.getJSON(getUrl, {
        BUID: buID,
        AID: aID,
        LID: lID
    }, function (response) {
        $('#Test').text("TEST");
    })
};

Controller:

public JsonResult GetMeasures(int buID) {
        return Json(new { Success = true });
    }

The Text of my span element doesn't get changed into "TEST".

Th1sD0t
  • 1,089
  • 3
  • 11
  • 37
  • `It's $('#Test').text("TEST");` – lshettyl Apr 02 '15 at 09:11
  • @LShetty Thanks for your response - but even with $('#Test').text("TEST"); it's not working. – Th1sD0t Apr 02 '15 at 09:13
  • You really need to explain _it's not working_ as I don't know what _it_ is! – lshettyl Apr 02 '15 at 09:15
  • @LShetty As described in the question I'd like to change a text in my view after the Json response "gets in" - so _it_ means that the call-back function of $.getJSON is not called at all. – Th1sD0t Apr 02 '15 at 09:17
  • try to change ".text" to ".html" so it should look like this: $('#Test').html('TEST'); – PhilSchneider Apr 02 '15 at 09:18
  • Put an `alert` inside the function and see if it works. Have an eye on the browser console/network as well to see what activitis take place. – lshettyl Apr 02 '15 at 09:20
  • Even with html instead of text the label didn't change... As I said the call-back function itself isn't called - even alert("Test") doesn't give any output. I rly don't get why - as I said my Controller Method gets definitely called. – Th1sD0t Apr 02 '15 at 09:23
  • @LShetty I've got it - I just forgot to set the JsonBehaviour to AllowGet - thanks mate! – Th1sD0t Apr 02 '15 at 09:27

1 Answers1

0

Send correct parameters:

$.getJSON(getUrl, {
        buID: buID
    }, function (response) {
        $('#Test').text("TEST");
    })
};

And then you need to use JsonRequestBehavior.AllowGet with JSON return, Also decorate your function with HttpGet attribute

[HttpGet]
public JsonResult GetMeasures(int buID) {
        return Json(new { Success = true }, JsonRequestBehavior.AllowGet);
}

A good read Why is JsonRequestBehavior needed?

Community
  • 1
  • 1
Satpal
  • 132,252
  • 13
  • 159
  • 168