$(document).ready(function(){
$('#EditCity').select2({
   ajax: {
          url: url_getcity,
          type: "get",
          dataType: 'json',
          delay: 250,
          data: function (params) {
             return {
                searchTerm: params.term // search term
             };
          },
          processResults: function (response) {
             return {
                results: response
             };		   
         },
          cache: true
        }
   });
    
   $('#EditCity').on('select2:select', function (e) {
        var city = e.params.data.id;
        console.log("here");
        $.ajax(url_getstatefromcity,{
           type : 'get',
           data :{'city' : city} ,
           success : function(data){
              
              $(document).find('#Districtedit').val(data.district.district_title);
              $(document).find('#Stateedit').val(data.state.state_title);
              $(document).find('#Stateedit').attr("data-state-id",data.district.state_id);
              $(document).find('#Statesedit').attr("data-state-id",data.district.state_id);
              $(document).find('#Districtedit').attr("data-district-id",data.district.districtid);
              $(document).find('#Countryedit').val("India");
              
           },
           error: function (jqXhr, textStatus, errorMessage) {
              console.log('Error' + errorMessage);
      }
        });
  });
  
  
   
  $('#EditShiopToCity').select2({
     ajax: {
            url: url_getcity,
            type: "get",
            dataType: 'json',
            delay: 250,
            data: function (params) {
               return {
                  searchTerm: params.term // search term
               };
            },
            processResults: function (response) {
               return {
                  results: response
               };		   
           },
            cache: true
          }
     });
     
     $('#EditShiopToCity').on('select2:select', function (e) {
          var city = e.params.data.id;
          console.log("here");
          $.ajax(url_getstatefromcity,{
             type : 'get',
             data :{'city' : city} ,
             success : function(data){
                
                $(document).find('#ShipToDistrictedit').val(data.district.district_title);
                $(document).find('#ShipToStateedit').val(data.state.state_title);
                $(document).find('#ShipToStateedit').attr("data-state-id",data.district.state_id);
                $(document).find('#ShipToDistrictedit').attr("data-district-id",data.district.districtid);
                $(document).find('#ShipToCountryedit').val("India");
                
             },
             error: function (jqXhr, textStatus, errorMessage) {
                console.log('Error' + errorMessage);
        }
          });
    });
    
    
   });