2

Im trying to ajaxification.Whenever i click on submit i need to refresh the page to get the result data in table.here is the code. ANd whenever i edit the data to change values, its creating another new entry in table.

$('.location-edit').click(function(){

    jQuery.ajax({
        url: "/smartfarm/control/getLocationJSON",
        type: "POST",
        data: {locationId:$(this).attr("data")},
        success: function(data) {
                $('#locationId').val(data.locations[0].locationId);
                $('#facilityId').val(data.locations[0].facilityId);
                $('#locationTypeId').val(data.locations[0].locationTypeId);
                $('#locationName').val(data.locations[0].locationName);
                $('#address').val(data.locations[0].address);
                $('#country').val(data.locations[0].country);
                $('#state').val(data.locations[0].state);
                $('#district').val(data.locations[0].district);
                $('#city').val(data.locations[0].city);
                $('#postalCode').val(data.locations[0].postalCode);
        }
    });
    $('#locationName').focus();
});

$('#location-submit').click(function(){
    $.ajax({
        url:'/smartfarm/control/saveLocation',
        type:'POST',
        data:$('#saveLocation').serialize(),
        success:function(result){
            jQuery.ajax({
                url: "/smartfarm/control/ajaxLocationList",
                type: "POST",
                data: {locationId:$('#locationId').val()},
                success: function(data) {
                    $('.location-list').html(data);
                    $('.loc-cre').show();
                    setTimeout(function() { $(".loc-cre").hide(); }, 5000);
                    $('.loc-del').hide();
                }
            });
        }
    });
});

$('.location-delete').click(function(){
var locId = $(this).attr("data")
    jQuery.ajax({
        url: "/smartfarm/control/deleteLocation",
        type: "POST",
        data: {locationId:locId},
        success: function(data) {
            jQuery.ajax({
                url: "/smartfarm/control/ajaxLocationList",
                type: "POST",
                data: {locationId:locId},
                success: function(data) {
                    $('.location-list').html(data);
                    $('.loc-del').show();
                    setTimeout(function() { $(".loc-del").hide(); }, 5000);
                    $('.loc-cre').hide();
                }
            });             
        }
    });
});

0 Answers0