locked
$.ajax method not returning any value RRS feed

  • Question

  • User1632102518 posted
    function fetchCurrentMapping() {
        var ddSource = $("#dicSourceName option:selected").text();
        var URL = "/api/HadoopData/FetchCurrentMapping";
        $.ajax({
            url: URL,
            type: 'GET',
            data: { ddSourceName: ddSource },
            contentType: "application/json",
            dataType: 'json',
            success: function (response) { 
                return response;
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(errorThrown);
            }
        });
    }
     [System.Web.Http.HttpGet]
            public List<DataDictToHive> FetchCurrentMapping(string ddSourceName)
            {
                DataDic2HiveMapping d = new DataDic2HiveMapping();
                return d.FetchCurrentMapping(ddSourceName);   
            }


    Even though API method returning List<DataDictToHive> , I am unable to see the response in Jquery. Can someone point me where I am wrong.Thanks.

    Tuesday, November 10, 2015 3:03 PM

Answers

  • User281315223 posted

    This looks like it would trigger an infinite loop (as your FetchCurrentMapping() method calls FetchCurrentMapping()), which could possibly present some issues but may not be the case :

    return d.FetchCurrentMapping(ddSourceName);

    If you want to actually see what your AJAX call is doing, it's best to take advantage of the Developer Tools (F12) available within your browser. Simply press F12 to open them and you can look at the Network tab to see your AJAX request take place. Better yet, you can use the debugger keyword in Javascript to essentially place a breakpoint in your Javascript that will be triggered when a particular statement is hit :

    success: function (response) { 
         debugger;
         // Placing a debugger keyword and running this code with the developer tools
         // open will allow you to hover over response to see what is being returned
         return response;
    },

    Generally when returning a collection in this manner, you'll need to actually access your data via the "d" property of your response :

    success: function (response) { 
         debugger;
         // Placing a debugger keyword and running this code with the developer tools
         // open will allow you to hover over response to see what is being returned
         var data = response.d;
         return data;
    },

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 10, 2015 4:02 PM

All replies

  • User281315223 posted

    This looks like it would trigger an infinite loop (as your FetchCurrentMapping() method calls FetchCurrentMapping()), which could possibly present some issues but may not be the case :

    return d.FetchCurrentMapping(ddSourceName);

    If you want to actually see what your AJAX call is doing, it's best to take advantage of the Developer Tools (F12) available within your browser. Simply press F12 to open them and you can look at the Network tab to see your AJAX request take place. Better yet, you can use the debugger keyword in Javascript to essentially place a breakpoint in your Javascript that will be triggered when a particular statement is hit :

    success: function (response) { 
         debugger;
         // Placing a debugger keyword and running this code with the developer tools
         // open will allow you to hover over response to see what is being returned
         return response;
    },

    Generally when returning a collection in this manner, you'll need to actually access your data via the "d" property of your response :

    success: function (response) { 
         debugger;
         // Placing a debugger keyword and running this code with the developer tools
         // open will allow you to hover over response to see what is being returned
         var data = response.d;
         return data;
    },

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 10, 2015 4:02 PM
  • User1632102518 posted

    Hi Rion,

    This helped me to identify the problem.Thanks.

    Tuesday, November 10, 2015 4:54 PM