JavaScript Ajax call returning empty response despite code behind returning correct data ajax call returning object object,ajax call returning empty response,

I'm doing something like:

 $.ajax({
    type: 'POST',
    dataType: 'json',
    contentType: 'application/json',
    url: '/Modal/getModalInfo',
    data: '{"machine":"' + machine + '"}',
    success: function (response) {
        modalData = response;
        fillModal();
    }
});

If I debug the C# and check the response being sent back to the JS, the data looks completely correct.

The reponse in the Ajax call is just:

response = Object {}

and completely empty. I am doing several other Ajax calls in the exact same way that are executing correctly.

Edit:

As far as what the C# is returning to Ajax:

        try {
            return Json(allInfo, JsonRequestBehavior.AllowGet);
        }
        catch (Exception ex) {
            return new JsonResult();
        }

"allinfo" looks like:

    AllTheInfo allInfo = new AllTheInfo();


    class AllTheInfo {
    List<DownTimes> dList;

    internal List<DownTimes> DList {
        get { return dList; }
        set { dList = value; }
    }
    List<PartsMade> pList;

    internal List<PartsMade> PList {
        get { return pList; }
        set { pList = value; }
    }

    PartsTotals pTotal;

    internal PartsTotals PTotal {
        get { return pTotal; }
        set { pTotal = value; }
    }
}

The classes that are referenced inside that class are other custom classes I've made.

Edit: I also modified my Ajax call to catch errors and it doesn't seem to think there are any errors, again, just an empty success response.

Edit again: I've now attempted to convert the object I'm returning to a Json string within C# using the following:

        string jsontext = "";
        try {
            jsontext = JsonConvert.SerializeObject(allInfo);

            System.IO.File.WriteAllText(path, jsontext);
        }
        catch (Exception ex) {
            Console.WriteLine(ex.Message);
        }

The problem now is that the call to JsonConvert is completing successfully (no error being caught) but the string is equal to "{}"

I'm not sure why this would be interpreted as successful.

Answer:1

I've seen this in the past when the client-side fails to parse the JSON coming back from the server due to syntax errors, additional text in the response (e.g. HTML tags etc.). Best bet is to use something like Fiddler (http://www.telerik.com/fiddler) or similar proxy to see exactly what's coming back in the response (not just what you're returning from the C# side as there may be additional filters, modules etc. affecting the output after it leaves your server-side method).

Answer:2

I want to override console.log method to invoke a set of tasks whenever console.log is called. I referred other Stackoverflow answers but that give me the error: Uncaught RangeError: Maximum call ...

I want to override console.log method to invoke a set of tasks whenever console.log is called. I referred other Stackoverflow answers but that give me the error: Uncaught RangeError: Maximum call ...

  1. override javascript console.log
  2. override console js
  3. javascript override console.error
  4. javascript override console.log function
  5. javascript override console

I'm writing a form in Angular and I have one criteria that requires that I need to check for that requires the input to ONLY contain letters and numbers AND the first character cannot be a number. Is ...

I'm writing a form in Angular and I have one criteria that requires that I need to check for that requires the input to ONLY contain letters and numbers AND the first character cannot be a number. Is ...

  1. angular form control validation
  2. angular form control set value
  3. angular form control disabled
  4. angular form control example
  5. angular form control get value
  6. angular form control reset
  7. angular form control name
  8. angular form control checkbox
  9. angular form control default value
  10. angular form control valuechanges
  11. angular form control array
  12. angular form control custom validator
  13. angular form control radio button
  14. angular form control seterrors
  15. angular form control clear value
  16. angular form control readonly
  17. angular form control focus
  18. angular form control change event
  19. angular form control label
  20. angular form control type

I have this Ajax to send multiple images: $('#btn').on("click", function () { var formData = new FormData($("#form1")[0]); var path = "php/upload/adm_prodpictures.php"; $....

I have this Ajax to send multiple images: $('#btn').on("click", function () { var formData = new FormData($("#form1")[0]); var path = "php/upload/adm_prodpictures.php"; $....

  1. javascript variable form data
  2. ajax send formdata and variable

I have a string like this: var variable = 'one|two|three|four|five'; This regex /^(\w+)\|/ matches first word (from left side). In other word, $1 returns one. Now I need to get second word from the ...

I have a string like this: var variable = 'one|two|three|four|five'; This regex /^(\w+)\|/ matches first word (from left side). In other word, $1 returns one. Now I need to get second word from the ...