Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have created web api in mvc4 now I am consuming it through j query in html page but it calls error function each time instead of success function following is the function

Java
function GetAllEmployee() {
           //$("#emps").empty();

           $.ajax({
               url: 'http://localhost:54374/api/Employee/';,
               type: 'GET',
               dataType: 'json',
               success: function (data) {
                   alert('yes');

                   for (var i = 0; i < data.length; i++) {

                       $("<table><tbody><tr></tr></tbody></table><table><tbody><tr><table><tbody><tr><table><tbody><tr><td></td></tr></tbody></table></tr></tbody></table></tr></tbody></table>" + data[i].Id + "<table><tbody><tr><table><tbody><tr><table><tbody><tr><td></td></tr></tbody></table></tr></tbody></table></tr></tbody></table>" + data[i].Name + "<table><tbody><tr><table><tbody><tr><table><tbody><tr><td></td></tr></tbody></table></tr></tbody></table></tr></tbody></table>" + data[i].Salary + "<table><tbody><tr><td>" + data[i].City + "</td></tr></tbody></table>").appendTo("#students");
                   }
               },
               error: function (xhr) {
                   alert('Some error occured');

                   alert(xhr);
               }
           });


       }

please help me how to use the fucntion to call function properly
Posted
Updated 8-Apr-14 7:36am
v2
Comments
anup.bhunia 8-Apr-14 14:51pm    
Could you please provide the code snippet of your web api? Is your api returning json object or something else?

 
Share this answer
 
You need to find out WHY it calls the error function.

Is there an exception ?

Open Developer tools (f12) and check the network tab and see the details of the call.

Also you have used the url 'http://localhost:54374/api/Employee/' do not use like this, use url in the following format : '/api/Employee/'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900