Created
November 27, 2013 09:17
-
-
Save jlcampana/7672885 to your computer and use it in GitHub Desktop.
Popurrí de llamadas AJAX con jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// AJAX CALL FOR DNI | |
function chequearDNI(dni) | |
{ | |
hideGrowl(); | |
hideDNI(); | |
$.getJSON('/ajax/dni/check/'+escapeHtml(dni)) | |
.done(function(json) | |
{ | |
var code = json.code; | |
if(code==1) | |
{ | |
var customer = json.customer; | |
$('#dni').val(json.customer.national_id); | |
$('#phone1').val(json.customer.phone_primary); | |
$('#cp').val(json.customer.postal_code); | |
$('#nombre_cliente').val(json.customer.name); | |
$('#direccion').val(json.customer.address); | |
$('#poblacion').val(json.customer.city); | |
$('#inputEmail').val(json.customer.email); | |
$('#phone2').val(json.customer.phone_secondary); | |
$('#ikea_family').val(json.customer.ikea_family); | |
$('#ikea_family').prop('checked', (json.customer.ikea_family == 1)); | |
if($('#ikea_family').prop('checked')) | |
{ | |
$('#boton_nuevo_ikea_family').hide(); | |
} | |
else | |
{ | |
$('#boton_nuevo_ikea_family').show(); | |
} | |
showDNI(true); | |
} | |
else | |
{ | |
showDNI(false); | |
} | |
}) | |
.fail(function(jqxhr, textStatus, error) | |
{ | |
var err = textStatus + ', ' + error; | |
console.log(jqxhr); | |
showGrowlWithMessage(err); | |
}); | |
} | |
// AJAX CALL FOR REFERENCES | |
function buscar(texto_buscar) | |
{ | |
$('#activity_indicator').show(); | |
$.get('/ajax/reserva/create/search/'+escapeHtml(texto_buscar)+'/'+i, | |
function(response, status, xhr) | |
{ | |
$('#boton_buscar_referencia').attr('disabled',false); | |
if (status == 'error') | |
{ | |
$('#activity_indicator').hide(); | |
showGrowlWithMessage('Error en función de buscar referencia :'+ xhr.status + ' ' + xhr.statusText); | |
} | |
else | |
{ | |
$("#activity_indicator").hide(); | |
if($.trim(response) != '') | |
{ | |
$('#search_result').replaceWith(response); | |
} | |
else | |
{ | |
showGrowlWithMessage('No se encontró la referencia'); | |
} | |
response=''; | |
i++; | |
$('#hidden_numero_referencias').val(i); | |
$('#boton_eliminar_todas').attr('disabled',false); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment