0

I don't know why this is happening since there are other functions in this page that use also getJSON and they do work. I have the following JavaScript Code

function openSOPNotesDialog() {

        var url = '<%: Url.Action("GetSOPNote", "SalesOrder") %>';
        var id = <%: Model.SodID %>;

        $.getJSON(url, { sodId : id }, function(data) {
            alert("data: " + data);
            $("#hidSOPSODId").val(data.SodID);
            $("#hidNoteId").val(data.NoteID);
            $("#txtSOPNotes").val(data.Description);
            $("#sopNotesDialog").dialog("open");
        });

    }

and then I have this method on the SalesOrderController class

public JsonResult GetSOPNote(int sodId)
        {
            var service = new SodSrv();
            var note = service.GetSOPNotes(sodId);
            return Json(note, JsonRequestBehavior.AllowGet);            
        }

However, the method is never called in the debugger and data is returned as null (which is what I'd expect). As I said before there are other calls in this page and they are also doing GET requests so I don't know what may be the cause.

4
  • once check your service and dao may be issue with those two files?
    – Kiran
    Oct 25, 2011 at 12:21
  • Check if it is sending/recieving response in your NET logger in IE Developer/Firebug Oct 25, 2011 at 12:25
  • you're sure the action response to datatype: json? Oct 25, 2011 at 12:25
  • if I call the URL directly I get the following response, which is what I expect {"NoteID":0,"SodID":0,"Note":"","LastUpdated":"\/Date(-2208988800000)\/","UpdatedByID":0,"UpdatedBy":null,"Active":true,"Deleted":false,"Description":"","Indirect":false,"Exception":{"Number":0,"Type":0,"Name":"","Details":""}} Oct 25, 2011 at 12:33

3 Answers 3

1

Sounds like the browser is pulling the data from the cache since it is a get request. Make sure to set no cache headers on the server if it is not meant to be cached.

0

Try adding an error handler to try to track down what the issue is:

$.ajax({
    dataType: 'json',
    url: url,
    data: { sodId : id },
    success: function(data) {
        alert("data: " + data);
        $("#hidSOPSODId").val(data.SodID);
        $("#hidNoteId").val(data.NoteID);
        $("#txtSOPNotes").val(data.Description);
        $("#sopNotesDialog").dialog("open");                        
    },
    error: function(jqXHR, textStatus, errorThrown) {
        alert("oops: " + textStatus + ": " + jqXHR.responseText);
    }
});
1
  • For some weird reason after changing it to the way you've written it here it worked. Even weirder is that now after reverting to how it was before it is working again. Could it have been something with IE Cache? Oct 25, 2011 at 12:42
0

I suspect that the reason is that getJSON uses get method and controllers normally allowed to accept only post methods. It's ease to check using any browser firebug for example.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.