remoteFill.js 616 B

123456789101112131415161718192021222324
  1. (function ($) {
  2. $.fn.remoteFill = function (target = false) {
  3. var location = $(this);
  4. let cep = $(this).parent().find('input').val();
  5. cep = String(cep).replace(/[^\d]/g, '');
  6. fetch('/postal/search/' + cep, {
  7. method: 'GET',
  8. headers: {
  9. 'Content-Type': 'application/x-www-form-urlencoded',
  10. 'X-Requested-With': 'fetch'
  11. }
  12. }).then(function (response) {
  13. let json = response.json();
  14. return json;
  15. }).then(function(json){
  16. target(json)
  17. });
  18. };
  19. })(jQuery);