Web api to jquery call
function GetAllContacts() {
$.ajax({
url: 'api/ContactsAPI',
type: 'GET',
dataType: 'json',
success: function (data) {
BindContacts(data);
},
error: function (error) {
debugger;
alert('Error Loading Contacts');
}
});
}
function GetContactForEdit() {
$.ajax({
url: 'api/ContactsAPI/' + $('#txtContactID').val(),
type: 'GET',
dataType: 'json',
success: function (data) {
$('#EditContactName').val(data.Name);
$('#EditAddress').val(data.Address);
$('#EditCity').val(data.City);
$('#EditState').val(data.State);
$('#EditZipcode').val(data.Zipcode);
},
error: function (error) {
debugger;
alert('Error Loading Contact');
}
});
}
function UpdateContact() {
var contact = {
ContactID: $('#txtContactID').val(),
Name: $('#EditContactName').val(),
Address: $('#EditAddress').val(),
City: $('#EditCity').val(),
State: $('#EditState').val(),
Zipcode: $('#EditZipcode').val()
};
$.ajax({
url: 'api/ContactsAPI/' + +$('#txtContactID').val(),
type: 'PUT',
data: JSON.stringify(contact),
contentType: "application/json;charset=utf-8",
success: function (data) {
alert('Contact updated Successfully');
},
error: function () {
alert('Contact was not Added');
}
});
}
function BindContacts(contacts) {
$('#contactList').empty();
$.each(contacts, function (index, contact) {
$('#contactList').append
("<li>" + contact.ContactID + " - "
+ contact.Name + "</li>");
});
}
function AddContact() {
var contact = {
Name: $('#ContactName').val(),
Address: $('#Address').val(),
City: $('#City').val(),
State: $('#State').val(),
Zipcode: $('#Zipcode').val()
};
debugger;
$.ajax({
url: 'api/ContactsAPI',
type: 'POST',
data: JSON.stringify(contact),
contentType: "application/json;charset=utf-8",
success: function (data) {
alert('Contact added Successfully');
GetAllStudents();
},
error: function () {
alert('Contact was not Added');
}
});
}
$.ajax({
url: 'api/ContactsAPI',
type: 'GET',
dataType: 'json',
success: function (data) {
BindContacts(data);
},
error: function (error) {
debugger;
alert('Error Loading Contacts');
}
});
}
function GetContactForEdit() {
$.ajax({
url: 'api/ContactsAPI/' + $('#txtContactID').val(),
type: 'GET',
dataType: 'json',
success: function (data) {
$('#EditContactName').val(data.Name);
$('#EditAddress').val(data.Address);
$('#EditCity').val(data.City);
$('#EditState').val(data.State);
$('#EditZipcode').val(data.Zipcode);
},
error: function (error) {
debugger;
alert('Error Loading Contact');
}
});
}
function UpdateContact() {
var contact = {
ContactID: $('#txtContactID').val(),
Name: $('#EditContactName').val(),
Address: $('#EditAddress').val(),
City: $('#EditCity').val(),
State: $('#EditState').val(),
Zipcode: $('#EditZipcode').val()
};
$.ajax({
url: 'api/ContactsAPI/' + +$('#txtContactID').val(),
type: 'PUT',
data: JSON.stringify(contact),
contentType: "application/json;charset=utf-8",
success: function (data) {
alert('Contact updated Successfully');
},
error: function () {
alert('Contact was not Added');
}
});
}
function BindContacts(contacts) {
$('#contactList').empty();
$.each(contacts, function (index, contact) {
$('#contactList').append
("<li>" + contact.ContactID + " - "
+ contact.Name + "</li>");
});
}
function AddContact() {
var contact = {
Name: $('#ContactName').val(),
Address: $('#Address').val(),
City: $('#City').val(),
State: $('#State').val(),
Zipcode: $('#Zipcode').val()
};
debugger;
$.ajax({
url: 'api/ContactsAPI',
type: 'POST',
data: JSON.stringify(contact),
contentType: "application/json;charset=utf-8",
success: function (data) {
alert('Contact added Successfully');
GetAllStudents();
},
error: function () {
alert('Contact was not Added');
}
});
}
Comments
Post a Comment