Skip to content

Instantly share code, notes, and snippets.

@AngeloR
Forked from anonymous/gist:1672186
Created January 24, 2012 19:58
Show Gist options
  • Save AngeloR/1672212 to your computer and use it in GitHub Desktop.
Save AngeloR/1672212 to your computer and use it in GitHub Desktop.
Jbom - pastebin.com/uEEvZEpK
//JAVASCRIPT
$(document).ready(function(){
CLICKIT_core.init();
CLICKIT_contract_form.init();
});
var CLICKIT_config = {
URLs : {
checkName : 'index.php/users/getnames'
}
}
var CLICKIT_ajax = {
checkName : function (name,callback){
$.ajax({
url: CLICKIT_config.URLs.checkName,
type: "POST",
async: true,
data: "name="+name,
dataType:"json",
success: function (data){
callback(data);
}
});
}
}
var CLICKIT_contract_form={
init:function(){
//Submit Event
$('#contract form#check_name').bind('submit',function(){
CLICKIT_contract_form.onSubmit();
return false;
});
},
onSubmit:function(){
var name = $('#contract form#check_name input[id="url"]').val();
if($.trim(name) != ""){
$('#contract form#check_name button span').addClass('loading');
$('#contract form#check_name button span').html('cargando');
CLICKIT_ajax.checkName(name,CLICKIT_contract_form.onReceive);
}
},
onReceive:function(data){
//myJson = eval("(" + data + ");");
$('#contract form#check_name button span').html('FIN');
//console.log(data.name);
console.log(data.result);
}
}
------------------------------------------------------
------------------------------------------------------
//PHP
public function getnames(){
$jsondata['name'] = $_POST['name'];
$jsondata['result'] = 'ok';
header('Content-type: application/json');
echo json_encode($jsondata);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment