locked
jQuery ajax method on success returning page content instead of json data RRS feed

  • Question

  • User2084211446 posted
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <script src="Scripts/jquery-1.10.2.min.js"></script>
    
        <script type="text/javascript">
            $(document).ready(function () {
                var ulEmployees = $("#ulEmp");
                $("#btnSubmit")
                .click(function () {
    
    
                    $.ajax({
                        type: "GET",
                        URL: "http://localhost:63380/api/EmployeeApi/GetEmployees", //checked, working fine in fiddler
                        datatype: "json",
                        success: function (data) {   // here data contains this page's content instead of json data
                           // data = JSON.parse(data);
                            $.each(data, function (index, val) {
                                var fullname = val.FirstName + " " + val.LastName;
                                ulEmployees.append("<li>" + fullname + "</li>");
                            });
    
                        }
    
    
    
                    });
                });
            });
                
           
        </script>
    </head>
    <body>
        Username: <input type="text" id="tbUsername" />
        <br />
        Password: <input type="text" id="tbPass" />
        <br /> <input type="submit" value="Submit"  id="btnSubmit"/>
        <br />
        <br />
        <ul id="ulEmp"></ul>
    </body>
    </html>

    My uri  returns json data. I verified it in fiddler, but when I make ajax call, on success, the data contains calling-page's content instead of json data. Any help much appreciated. 

    Thanks,

    Rose

    Tuesday, December 20, 2016 3:23 PM

Answers

  • User527778624 posted

    Hi,

    JS is case-sensitive, try updating URL to url and datatype to dataType.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 20, 2016 6:05 PM

All replies

  • User527778624 posted

    Hi,

    JS is case-sensitive, try updating URL to url and datatype to dataType.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 20, 2016 6:05 PM
  • User2084211446 posted

    Thanks Raju!!!

    Best,

    Rose  :)

    Tuesday, December 20, 2016 10:22 PM