how to make address fields autocomplete

Hi,

I am trying to make city, state, country autocomplete according to postal code.

i have written a on change JavaScript  but its not work.

i think  the function is not able to call php file.

This my code..please help me

$('#primary_address_postalcode').change(function(){
var pin = $(this).val();

$.ajax({
type:'POST',
url:'SugarCE/SugarCE2/ajaxData.php',
data:'pin='+pin,
dataType: 'json',
success:function(data){

alert(data);

document.getElementById('primary_address_city').value =data[1];
document.getElementById('primary_address_state').value =data[2];
document.getElementById('primary_address_country').value =data[3];
},
error: function(msg)
{
alert(" Error ");
}
});

});

Thank You in Advance

Parents
  • Hi,

    Please use the following code:

    $.ajax({
               url: "index.php",
               type: "POST",
               dataType: "html",
               data: "module=[MODULE-NAME]&action=[ACTION-NAME]&sugar_body_only=true&[PARAM-NAME]=" + [PARAM-VALUE] ,
               async: true,
               cache: false,
               success: function (response)
               {
    console.log(response);
       }
    });

    In SugarCRM CE we call actions not files through ajax. Actions can be created in modules controller or a simple php file in a module directory behave same like an action.
    e.g custom/modules/Contacts/autofillAddress.php

    and we can call this action.

    $.ajax({
               url: "index.php",
               type: "POST",
               dataType: "html",
               data: "module=COntacts&action=autofillAddress&sugar_body_only=true&postal_code=63000" ,
               async: true,
               cache: false,
               success: function (response)
               {
    console.log(response);
       }
    });

    Hope this helps.

    Regards,

    RT

Reply
  • Hi,

    Please use the following code:

    $.ajax({
               url: "index.php",
               type: "POST",
               dataType: "html",
               data: "module=[MODULE-NAME]&action=[ACTION-NAME]&sugar_body_only=true&[PARAM-NAME]=" + [PARAM-VALUE] ,
               async: true,
               cache: false,
               success: function (response)
               {
    console.log(response);
       }
    });

    In SugarCRM CE we call actions not files through ajax. Actions can be created in modules controller or a simple php file in a module directory behave same like an action.
    e.g custom/modules/Contacts/autofillAddress.php

    and we can call this action.

    $.ajax({
               url: "index.php",
               type: "POST",
               dataType: "html",
               data: "module=COntacts&action=autofillAddress&sugar_body_only=true&postal_code=63000" ,
               async: true,
               cache: false,
               success: function (response)
               {
    console.log(response);
       }
    });

    Hope this helps.

    Regards,

    RT

Children
No Data