I have a simple <button type="submit" onClick="dothis();">Click</button>.
This script below have no problem,
$(document).ready(function() {
action = 'test';
$.ajax({
url:'ajax.php',
data: 'action='+action,
type:'GET',
dataType:'json',
timeout:7000,
error:function(){ alert('Error!'); return false; },
success:function(json){ alert('ok'); }
});
});
but when I put it into function then it doesn't work,
function dothis(){
action = 'test';
$.ajax({
url:'ajax.php',
data: 'action='+action,
type:'GET',
dataType:'json',
timeout:7000,
error:function(){ alert('Error!'); return false; },
success:function(json){ alert('ok in function'); }
});
}
What was the correct way to put ajax into a function ?
account_register()somewhere? FYI, your first example is in a function too.<button type="submit" onClick="dothis(); return false;">Click</button>