Click here to Skip to main content
14,240,210 members
Rate this:
Please Sign up or sign in to vote.
See more:
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

function GetAllEmployee() {

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

                   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');



please help me how to use the fucntion to call function properly
Updated 8-Apr-14 7:36am
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?
Rate this:
Please Sign up or sign in to vote.

Solution 1

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/'

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100